public class Quiz{
//Make various questions with correct/incorrect options
/*
* Suggestion
* Question 1
* How old was the first king of sweden when he passed?
* Options1
* 40
* 60
* 80
*/
public static int correctAnswer = 40;
public static int guess = Convert.ToInt32(Console.ReadLine());
public static void Guess(){
System.Console.WriteLine("How old was the 1st King of Sweden\n");
System.Console.WriteLine("when he passed away?");
while(guess != correctAnswer){
if(guess == correctAnswer){
System.Console.WriteLine("Correct answer. Congratulations.");
} else{
System.Console.WriteLine("Try again.");
}
}
}
}
Я пробовал перейти с do- while на while, но это не помогло.
Я хочу, чтобы код продолжал работать до тех пор, пока пользователь не угадает правильный ответ. Однако код бесконечно выполняет что-то еще. [code]public class Quiz{ //Make various questions with correct/incorrect options /* * Suggestion * Question 1 * How old was the first king of sweden when he passed? * Options1 * 40 * 60 * 80 */ public static int correctAnswer = 40; public static int guess = Convert.ToInt32(Console.ReadLine());
public static void Guess(){ System.Console.WriteLine("How old was the 1st King of Sweden\n"); System.Console.WriteLine("when he passed away?"); while(guess != correctAnswer){ if(guess == correctAnswer){ System.Console.WriteLine("Correct answer. Congratulations."); } else{ System.Console.WriteLine("Try again."); } } } } [/code] Я пробовал перейти с do- while на while, но это не помогло.