我无法弄清楚为什么我的字符串重新启动会更改为"否"无论我在这一点上输入什么:
while (
(restart != "YES") && (restart != "NO")
)
非常感谢任何帮助。
do
{
//main part of program
Console.Write("Do you wish to calculate another? (YES/NO) ");
restart = Console.ReadLine();
restart = qualified.ToUpper();
while ((restart != "YES") && (restart != "NO")) //????
{
Console.WriteLine("Error");
Console.WriteLine("Do you wish to calculate another? (YES/NO) ");
restart = Console.ReadLine();
restart = qualified.ToUpper();
}
} while (restart == "YES");
答案 0 :(得分:2)
qualified.ToUpper()
,因此保持不变。无论用户输入什么,您的restart
变量始终会被赋予相同的值。拿出来然后使用:
do
{
//main part of program
Console.Write("Do you wish to calculate another? (YES/NO) ");
restart = Console.ReadLine().ToUpper();
while ((restart != "YES") && (restart != "NO")) //????
{
Console.WriteLine("Error");
Console.WriteLine("Do you wish to calculate another? (YES/NO) ");
restart = Console.ReadLine().ToUpper();
}
} while (restart == "YES");
答案 1 :(得分:1)
删除以下代码:
restart = qualified.ToUpper();