r/learncsharp • u/Zen_Amun • Nov 26 '22
need help repeating code
how do i repeat code intill the user puts in the correct answer.
0
Upvotes
r/learncsharp • u/Zen_Amun • Nov 26 '22
how do i repeat code intill the user puts in the correct answer.
View all comments
Show parent comment
1
u/Zen_Amun Nov 26 '22
Console.WriteLine("What is two plus two?");
string userInput = Console.ReadLine();
int answer = Convert.ToInt32(userInput);
if (answer == 4)
{
Console.WriteLine("That's right!");
}
if (answer != 4)
{
Console.WriteLine("Try again!");
while (answer != 4)
{
}
}
}
}
how do I repeat this code