我正在创建一个计算不同日子里不同水果价格的程序。我现在有两种水果(香蕉和苹果)。当我输入“苹果”时,星期几和数量只给出苹果的价格。问题是,当我输入“香蕉”时,工作日和数量给了我香蕉和苹果的价格。(C#)If-Else Statement Issue Issue
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FruitShop
{
class Program
{
static void Main(string[] args)
{
var fruit = Console.ReadLine();
var weekday = Console.ReadLine();
var quantuty = double.Parse(Console.ReadLine());
if (fruit == "banana")
{
if (weekday != "saturday" && weekday != "sunday")
Console.WriteLine(quantuty * 2.50);
if (weekday == "saturday")
{
Console.WriteLine(quantuty * 2.70);
}
if (weekday == "sunday")
{
Console.WriteLine(quantuty * 2.70);
}
}
else if (fruit == "apple")
{
if (weekday != "saturday" && weekday != "sunday")
Console.WriteLine(quantuty * 1.20);
}
{
if (weekday == "saturday")
{
Console.WriteLine(quantuty * 1.25);
}
if (weekday == "sunday")
{
Console.WriteLine(quantuty * 1.25);
}
}
}
}
}
您是周六和周日病例不在苹果内部 - 如果条件大括号。 – Filburt
谢谢!它现在有效!我会再次检查我的语法:) – HrNik
使用[StyleCop](https://stylecop.codeplex.com/)(免费)或ReSharper(付费) - 他们会指出模糊的格式,可能会导致意想不到的行为。 – Filburt