Hi everyone, I'm a beginner to programming. I have a simple query which I've been struggling with...
I'm not totally sure how to loop round the switch statement so that once one of the cases has been selected, the program loops back to the command line so it's ready for the next input command from the user. Part of the code I'm using is below.
Thanks,
Ryan
Code:
C#
Console.WriteLine("Please select one of the following options to sort the score table: Highest, Lowest, Average, Total");
string sortScore = Console.ReadLine();
while (sortScore != "exit")
{
switch (sortScore)
{
case "Highest": //Do highest instructions here
//Go back to top of while statement to input next command
default:
Code
Console.WriteLine("Invalid command");
Console.ReadLine();
break;
}
}
Antony Gouldsbrough2 pointsPosted Oct 19, 2006, 1:03 PM EDT
static void Main(string[] args)
{ Console.WriteLine("Please select one of the following options to sort the score table: Highest, Lowest, Average, Total");
string sortScore = "";
bool UserExited = false;
while (!UserExited)
{ sortScore = Console.ReadLine();
switch (sortScore)
{ case "Highest":
Console.WriteLine("highest score=100");
break;
case "exit":
UserExited = true;
break;
default:
Console.WriteLine("Invalid command");
break;
}
}
}