I am currently looking for a solution for this c# console application function
I tried searching for a method for creating a while loop that can terminate for the co
One option can be to create method and keep calling until valid input comes:
public static void ProcessInput(string input)
{
int choice = Convert.ToInt32(input);
switch (choice)
{
case 1:
Console.WriteLine("");
Console.WriteLine("You have chosen Defult Empire 1");
break;
case 2:
Console.WriteLine("");
Console.WriteLine("You have chosen Defult Empire 2");
break;
case 3:
Console.WriteLine("");
Console.WriteLine("You have chosen Defult Empire 3");
break;
case 4:
Console.WriteLine("");
Console.WriteLine("You have chosen Defult Empire 4");
break;
default:
Console.WriteLine("");
Console.WriteLine("Input Invalid, Please press the number from the corresponding choices to try again");
ProcessInput(Console.ReadLine());
break;
}
and in your main program:
public static void Main()
{
Console.WriteLine("Hello World");
ProcessInput(Console.ReadKey());
}