【发布时间】:2015-01-02 02:34:05
【问题描述】:
static void Main(string[] args)
{
int output = 0;
int number = 0;
Console.WriteLine("Please input a number for it to be counted!");
bool conversion = int.TryParse(Console.ReadLine(), out output);
if( number >= 1000)
{
while (number <= output)
{
switch (conversion)
{
case true:
Console.Write(number + " ");
number += 2;
break;
case false:
Console.WriteLine("ERROR INVALID INPUT!");
break;
}
}
}
else
{
Console.WriteLine("APPLICATION ERROR: NUMBER MUST BE BELOW OR AT 1000 TO PREVENT OVERFLOW!");
}
string choice = Console.ReadLine();
do // Here is the beginning of the do code
{
Console.WriteLine("Do you want to continue - Yes or No");
if(choice.ToUpper() != "NO" && choice.ToUpper() != "NO");
{
Console.WriteLine("ERROR INVALID INPUT: Only input Yes or No!");
}
}while(choice.ToUpper() != "YES" && choice.ToUpper() != "NO");
}
}
}
这是一个非常简单的应用程序,尚未完成,但它的作用是输入一个小于或等于 1000 的数字,它会均匀地计数。我唯一的问题是代码末尾的 do 语句。它尚未完成,但根据我的研究,do 语句已完成,如果用户没有输入是或否,它会向他们显示该错误,然后再次询问“你想再去一次吗”但是因为这个 do 语句我输入了 10 之类的任何数字,它给了我一个错误,说它超过 1000,然后继续说“错误无效输入:只有输入是或否!”的无限循环。我该如何解决这个问题?
【问题讨论】:
-
哇,在循环内的布尔值上使用
switch()语句。壮观的 WTF。
标签: c# loops while-loop