OKay, so I'm new to the whole do while loop thing, and I'm trying to make a main menu, here's my code below:
int main()
{
int choice;
char sure;
bool quit = false;
char ctrl;
do
{
cout << "Main Menu." << endl
<< "1. New Game." << endl
<< "2. Load Game." << endl
<< "3. Exit." << endl
<< "Your choice: ";
cin >> choice;
if (choice == 1)
{
cout << "Are you sure you wish to start a new game? (Y/N) ";
cin >> sure;
if (sure != 'N' || sure != 'n')
{
ctrl = 'a';
quit = true;
}
}
else if ( choice == 2)
{
ctrl = 'b';
quit = true;
}
else
quit = true;
}
}
while (quit == true);
if (ctrl = 'a')
cout << "New Game." << endl;
else if (ctrl = 'b')
cout << "Load Game." << endl;
else
cout << "Goodbye." << endl;
return 0;
}
there are a few getchar() thrown in there. But the only problem is as you'll probably figure out is that after I do everything it just restarts again, and not exit the loop. What is the problem in the code?
Thanks
while(quit == true)withwhile(!quit), and start thinking about what that means for the rest of the code. Cheers & hth.,