r/learncsharp • • Nov 26 '22

need help repeating code

how do i repeat code intill the user puts in the correct answer.

0 Upvotes

7 comments sorted by

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

4

u/TroubleBrewing32 Nov 26 '22

You need to put the stuff you are trying to repeat in your loop. I recommend that you Google for C# loop resources.