vendredi 31 juillet 2020

Prevent that people type anything else then [Y or N] [duplicate]

I need to make something that can prevent that people type anything else then [Y or N] (Maby an if statement and a loop)

while(true)
{

//The main program is up here

Console.WriteLine("Do you want to play again? [Y or N]");

string answer = Console.ReadLine().ToUpper();

if (answer == "Y")
{
continue;
}
else if (answer == "N")
{
return;
}

//maybe here

}

Aucun commentaire:

Enregistrer un commentaire