I'm sorry if something like this has already been posted. I looked through a couple of the threads and they were similar to my problem but not quite.
This is part of my code.
Code:
int main()
{
cout << "Hi! What's your name? \n";
cin >> UserName;
cout << "\nWelcome, " << UserName << "!\a" << endl;
MainMenu();
}
int Loop()
{
if (loop1 == true)
{
MainMenu();
}
if (loop1 == false)
{
//Do Nothing...
}
return 0;
}
int MainMenu()
{
cout << "\nChoose Wisely...\n";
cout << "[1] Quake\n";
cout << "[2] Unreal\n";
cout << "[3] Half-Life\n";
cout << "[4] Others\n";
cout << "[5] Explore the CD\n";
cin >> GamePref;
if (int(GamePref) == 1)
{
cout << "\a" << endl;
QuakeMenu();
loop1 = false;
}
else if (int(GamePref) == 2)
{
cout << "\a" << endl;
UnrealMenu();
loop1 = false;
}
else if (int(GamePref) == 3)
{
cout << "\a" << endl;
HLMenu();
loop1 = false;
}
else if ((GamePref < 1) || (GamePref > 5))
//Ok I know here is a problem because I need to
//specify that GamePref should not be a character either
//(Heh how would I do that?) Is it "&& (!=isalpha(GamePref)"?...
{
cout << "\nWrong Number!\n";
Loop();
loop1 = true;
}
else if (isalpha(GamePref))
{
cout << "\nThat's not a number!\n";
Loop();
loop1 = true;
}
return 0;
}
My biggest problem is that if I were to enter in the wrong number or a letter. The program would end. I've tried this several different ways, using while statements, case statements, ect. and the only thing I've been able to do is either A) The program closes after the wrong value is typed OR B) The program loops back and forth between MainMenu and WhateverMenuYouSelected every second. So I guess my question is "How do I get the CIN twice without having my program take the first input?"