C
CoolMuffin
Guest
Hello,
So I am coding c sharp and I have got my code to say that if the user enter either 1,2 or 3 a different outcome happens but then I realised that what happens if the user enters a different number to 1,2 or 3...
So I want to know how I can create a loop for my command until the user inputs the correct number?
Thanks
Console.Write("What is your name: ");
string name = Console.ReadLine();
Console.WriteLine("Welcome " + name + " to the Spelling Game");
Console.WriteLine("Enter 1 for Beginner");
Console.WriteLine("Enter 2 for Intermediate");
Console.WriteLine("Enter 3 for Advanced");
int result;
if (int.TryParse(Console.ReadLine(), out result))
{
if (result == 1)
Console.WriteLine("Welcome to Beginner, " + name);
else if (result == 2)
Console.WriteLine("Welcome to Intermediate, " + name);
else if (result == 3)
Console.WriteLine("Welcome to Advanced, " + name);
else
Console.WriteLine("Incorrect Response");
Continue reading...
So I am coding c sharp and I have got my code to say that if the user enter either 1,2 or 3 a different outcome happens but then I realised that what happens if the user enters a different number to 1,2 or 3...
So I want to know how I can create a loop for my command until the user inputs the correct number?
Thanks
Console.Write("What is your name: ");
string name = Console.ReadLine();
Console.WriteLine("Welcome " + name + " to the Spelling Game");
Console.WriteLine("Enter 1 for Beginner");
Console.WriteLine("Enter 2 for Intermediate");
Console.WriteLine("Enter 3 for Advanced");
int result;
if (int.TryParse(Console.ReadLine(), out result))
{
if (result == 1)
Console.WriteLine("Welcome to Beginner, " + name);
else if (result == 2)
Console.WriteLine("Welcome to Intermediate, " + name);
else if (result == 3)
Console.WriteLine("Welcome to Advanced, " + name);
else
Console.WriteLine("Incorrect Response");
Continue reading...