Hey guys, I am writing a program which uploads a text file into a linked list then displays a menu prompt to the user. All of my functions work fine except when I try to exit the menu/program. The program crashes and I don't see where it is coming from. Please help me to see and understand why my program is behaving as such. Here is the menu function:
void menuSelection(BankAccounts h)
{
int selection;
cout << "=============== Menu ===============" << endl;
cout << "1) Show current balance" << endl;
cout << "2) Deposit" << endl;
cout << "3) Withdrawal" << endl;
cout << "4) Display All Accounts" << endl;
cout << "5) Exit" << endl;
cout << "Menu Selection: ";
cin >> selection;
while( cin.fail() || selection < 1 || selection > 5)
{
cin.clear();
cin.ignore(10, '\n');
cout << "Error: Invalid menu selection" << endl;
cout << "Menu Selection: ";
cin >> selection;
}
if (selection == 1)
{
h.showMyBalance();
menuSelection(h);
}
else if (selection == 2)
{
h.makeDeposit();
menuSelection(h);
}
else if (selection == 3)
{
h.makeWithdrawal();
menuSelection(h);
}
else if (selection == 4)
{
h.showAll();
menuSelection(h);
}
else if (selection == 5)
{
cout << "Have a nice day" << endl << endl;
}
}
and here is how it is called in main()
int main()
{
BankAccounts h;
h.loadDataBase();
menuSelection(h);
return 0;
}
why is it when I choose 5, that the program crashes instead of passing control back to main and executing the next instruction which would be return 0? All other menu selections work without any errors.
Thanks for taking the time to read this, and thank you for your help in advance!