【发布时间】:2010-09-17 04:31:16
【问题描述】:
如何让控制台应用程序运行直到用户输入“Q”、“q”、“Quit”或“quit”来终止它?
这是我当前的代码:
public class Class1
{
[STAThread]
static void Main(string[] args)
{
string userName;
int i = 0, totalCal = 0, cal = 1;
Console.WriteLine("Welcome to the magical calorie counter!");
Console.WriteLine();
Console.Write("Enter in your name -> ");
userName = Console.ReadLine();
for (i = 0; i <= 10; i++)
{
Console.WriteLine("Hello {0}.....Let's add some calories!!", userName);
}// end for loop
Console.WriteLine();
while (cal != 0)
{
Console.Write("Enter some Calories:<or 0 to quit>: ");
cal = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("You entered {0}", cal);
Console.WriteLine();
totalCal += cal;
Console.WriteLine();
Console.WriteLine("-------------------So far you have a total of {0}------------------", totalCal);
Console.WriteLine();
Console.WriteLine();
}// end of while
}// end of amin
}//end of class
【问题讨论】:
-
我建议你问这个:programmers.stackexchange.com
-
Ctrl + C 是迄今为止最好的:)
-
“尊敬的先生和/或女士,我分别希望停止使用此计算机程序。我要求从此程序中的所有活动停止。感谢您对此事的考虑。你的,Z。”
-
只有我能理解这个问题吗?他想知道如何通过键入其中一个命令来退出程序。
-
没错,我只是没有正确解释。很抱歉造成混乱。
标签: c# console-application exit