当我运行此代码时,输入我的输入,由于某种原因我没有收到任何类型的输出。
这是我的代码:
string fruit = Console.ReadLine();
double quantity = double.Parse(Console.ReadLine());
string day = Console.ReadLine();
if (day == "Monday" || day == "Tuesday"|| day == "Wednesday" || day == "Thursday" || day == "Friday")
{
switch (fruit)
{
case "banana": Console.WriteLine(Math.Round(2.50*quantity,2)); break;
case "apple": Console.WriteLine(Math.Round(1.20 * quantity, 2)); break;
case "orange": Console.WriteLine(Math.Round(0.85 * quantity, 2)); break;
case "grapefruit" : Console.WriteLine(Math.Round(1.45 * quantity, 2)); break;
case "kiwi": Console.WriteLine(Math.Round(2.70 * quantity, 2)); break;
case "pineapple": Console.WriteLine(Math.Round(5.50 * quantity, 2)); break;
case "grapes": Console.WriteLine(Math.Round(3.85* quantity, 2)); break;
default: Console.WriteLine("error"); break;
}
}
else if (day == "Saturday" || day == "Sunday")
{
switch (fruit)
{
case "banana": Console.WriteLine(Math.Round(2.70 * quantity, 2)); break;
case "apple": Console.WriteLine(Math.Round(1.25 * quantity, 2)); break;
case "orange": Console.WriteLine(Math.Round(0.90 * quantity, 2)); break;
case "grapefruit": Console.WriteLine(Math.Round(1.60 * quantity, 2)); break;
case "kiwi": Console.WriteLine(Math.Round(3.00 * quantity, 2)); break;
case "pineapple": Console.WriteLine(Math.Round(5.60 * quantity, 2)); break;
case "grapes": Console.WriteLine(Math.Round(4.20 * quantity, 2)); break;
default: Console.WriteLine("error"); break;
}
}
如果你们中的任何人能帮助我,我将非常感激。
答案 0 :(得分:1)
您正在获得输出 - 只是应用程序完成得太快,您无法看到它。只需在方法的最后添加以下行,即可在退出前使应用程序暂停输入:
Console.ReadLine();
答案 1 :(得分:0)
你也可以使用 Console.ReadKey();
如果您在Visual Studio中运行没有调试的程序,请按 Ctrl + F5 ,因此它将在结束时停止,并且在您点击任何控制台后将关闭控制台键。