小编ber*_*y11的帖子

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

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

例如,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 * …
Run Code Online (Sandbox Code Playgroud)

c# debugging

2
推荐指数
1
解决办法
131
查看次数

标签 统计

c# ×1

debugging ×1