I always thought that if I used a switch statement and enter an option not specified the default would catch it. However, if I press enter then enter an option I get a run time error. How would I fix this? I am only including part of the code, if you want to see the rest I can post the rest.
public enum Options : byte
{
newZ = 1,
display,
Exit
}
static void displayMenu()
{
Console.WriteLine("Enter newZ to try new integers");
Console.WriteLine("Enter display to see which Range Checker has the most Z's under the range");
Console.WriteLine("Enter Exit to exit");
}
static void Main(string[] args)
{
RangeChecker[] rangeChecker = new RangeChecker[20];
Random random = new Random();
const int SIZE = 20;
initialize(rangeChecker, SIZE);
order(rangeChecker, SIZE);
for (; ; )
{
displayMenu();
string volString = Console.ReadLine();
Options options = (Options)Enum.Parse(typeof(Options), volString);
switch (options)
{
case Options.newZ:
addZ(rangeChecker, SIZE);
break;
case Options.display:
display(rangeChecker, SIZE);
break;
case Options.Exit:
Console.WriteLine("Goodbye");
System.Environment.Exit(1);
break;
default:
Console.WriteLine("entry must be addZ, display, or Exit");
break;
}
}
}
}
}