>>but how do I keep the program from crashing?
Clean up if cin has an error by first clearing the stream of errors and then discarding the junk input and starting over with a clean slate, then jump back to the beginning of the loop and try again
Code:
void Menu1()
{
cout << "\nSelect a command:";
for ( ; ; )
{
bool exit = false;
cout << "\n1 - Go Exploring";
cout << "\n2 - Exit";
cout << "\nCommand: ";
int input;
cin >> input;
if (!cin)
{
cin.clear();
while (cin.get() != '\n')
{}
continue;
}
switch (input)
{
case 1: cout << "\nOne!";
break;
case 2: exit = true;
break;
default: cout << "\nThat wont work.";
break;
}
if (exit)
break;
}
}
>>Use a character array
That's a waste, using a 100 character array just so that you can use the first one and ignore the others.
>>gets(choice);
You risk a buffer overflow this way, since this is C++ you might as well use getline and be safe. C++ is hard enough without forcing more difficulties into things. :-)
Code:
cin.getline(choice, 100);