Thank you.
I wanted to use TryParse, but I didn't know how to let the user keep trying until they enter a number, til I tried it. The following code seems to work correctly. There is a switch statement where the user must enter 1, 2, or 3. Should I put a default in the switch statement?
csharp
int game;
//if they didn't enter a number, return 0
int.TryParse(Console.ReadLine(), out game);
while (game <= 0 || game > 3)
{
Console.WriteLine("You must enter either 1, 2, or 3.");
int.TryParse(Console.ReadLine(), out game);
}
//do stuff, since they entered a number
There are several places in the program where the user is asked to input a number. Would it be more efficient to use a method
such as PsychoCoder's IsNumeric() , or to keep doing it as I have done this?
edit--I almost never get it right the first time. Forgot the error message, and then some other stuff. lol
This post has been edited by OliveOyl3471: 23 May, 2008 - 07:08 PM