为什么这段代码不能打印任何东西?

ber*_*y11 2 c# debugging

我正在尝试创建一个工作程序,您必须输入城镇,产品和数量并输出总价.

例如,Town1> Milk> 2应该导致2.但由于某种原因,没有产出.有人可以帮帮我,告诉我这个错误吗?

这是代码:

Console.Write("Enter product: ");
var product = Console.ReadLine().ToLower();
Console.Write("Enter town: ");
var town = Console.ReadLine().ToLower();
Console.Write("Enter quantity: ");
var quantity = double.Parse(Console.ReadLine());

if (town == "Town1")
{
    if (product == "Milk")
        Console.WriteLine(1.50 * quantity);
    if (product == "Water")
        Console.WriteLine(0.80 * quantity);
    if (product == "Whiskey")
        Console.WriteLine(4.20 * quantity);
    if (product == "Peanuts")
        Console.WriteLine(0.90 * quantity);
    if (product == "Chocolate")
        Console.WriteLine(2.60 * quantity);   
}
if (town == "Town2")
{
    if (product == "Milk")
        Console.WriteLine(1.40 * quantity);
    if (product == "Water")
        Console.WriteLine(0.70 * quantity);
    if (product == "Whiskey")
        Console.WriteLine(3.90 * quantity);
    if (product == "Peanuts")
        Console.WriteLine(0.70 * quantity);
    if (product == "Chocolate")
        Console.WriteLine(1.50 * quantity);
}
if (town == "Town3")
{
    if (product == "Milk")
        Console.WriteLine(1.90 * quantity);
    if (product == "Water")
         Console.WriteLine(1.50 * quantity);
    if (product == "Whiskey")
         Console.WriteLine(5.10 * quantity);
    if (product == "Peanuts")
         Console.WriteLine(1.35 * quantity);
    if (product == "Chocolate")
         Console.WriteLine(3.10 * quantity);
}
}}}
Run Code Online (Sandbox Code Playgroud)

Rya*_*son 7

您设置town = value.ToLower()product = value.ToLower(),这使得所有字符小写,改变这些行:

var town = Console.ReadLine().ToLower();
var product = Console.ReadLine().ToLower();
Run Code Online (Sandbox Code Playgroud)

对此:

var town = Console.ReadLine();
var product = Console.ReadLine();
Run Code Online (Sandbox Code Playgroud)

或者更改if语句条件以使用小写值作为比较

if (town == "town1")
{
Run Code Online (Sandbox Code Playgroud)

等等...