【发布时间】:2013-01-29 17:12:41
【问题描述】:
我想制作一个程序,随机问用户 5 个问题而不重复问题,如果问题是正确的,如果错误则继续下一个问题,直到他给出正确的答案,这就是我的代码已经写了,但是还是有一些问题,比如有重复,当用户输入错误的答案时,它只会停止一次,然后程序就关闭了! 现在如何防止重复相同的问题,如果他输入错误的值不要继续下一个问题或程序关闭?
static void Main()
{
next:
Random question = new Random();
int x = question.Next(5);
string[] array = new string[5];
array[0] = "-What is the capital of France";
array[1] = "-What is the capital of Spain";
array[2] = "-What is the captial of Russia";
array[3] = "-What is the capital of Ukraine";
array[4] = "-What is the capital of Egypt";
Console.WriteLine(array[x]);
string[] answer = new string[5];
answer[0] = "Paris";
answer[1] = "Madrid";
answer[2] = "Moscow";
answer[3] = "Kiev";
answer[4] = "Cairo";
string a = Console.ReadLine();
if (a == answer[x])
{
Console.WriteLine("It's True \n*Next Question is:");
goto next;
}
else
Console.WriteLine("It's False \n*Please Try Again.");
Console.ReadLine();
}
【问题讨论】:
-
请提出具体问题(如有必要,请提出多个问题),而不是“这不起作用,请修复”类型之一。也请删除此
goto。 -
天啊,请不要使用 GOTO。 That's the Devil himself
-
@ken2k .. 我已经更新了这个问题并这样做了! :)
-
@HighCore .. 我可以用什么代替?!
-
@user2022523 Flow Control
标签: c#