HELP..
below is part of my code which
i have trouble with it
why when i choose 5 to exit..
it does not exit..but it will ask me to press any key to continue
then when i press...it cum back to the main menu again..
thx for helping...really appreciate it
#include <iostream>
using namespace std;
void PressAnyKeyToContinue(void)
{
system("pause");
system("cls");
}
int MainMenu(void)
{
int choice=0;
bool gotInput = false;
cout << "==========================================" << endl;
cout << " Personal Financial Record Keeping System " << endl;
cout << "==========================================" << endl;
cout << "1. Update Income" << endl;
cout << "2. Update Fixed Expenses" << endl;
cout << "3. Update Variable Expenses" << endl;
cout << "4. Calculate Totals" << endl;
cout << "5. Exit" << endl;
cout << "==========================================" << endl;
do
{
cout << "Please input your choice:";
if(!(cin >> choice))
{
cin.clear();
cin.ignore(10000,'\n');
gotInput = true;
}
if (choice >= 1 && choice<=9) gotInput = true;
} while(!gotInput);
return choice;
}
int main()
{
int choice;
bool flag = false;
do{
choice = MainMenu();
system("cls");
if (choice == 1) updateIncome();
else if (choice == 2) updateFixedExpenses();
else if (choice == 3) updateVariableExpenses();
else if (choice == 4) calcTotal();
else if (choice == 5) flag = true;
else cout << "Use only number shown in the menu" << endl;
if(!flag) PressAnyKeyToContinue();
}while (!flag);
system ("pause");
return 0;
}