#include <iostream>
#include "bankingSystem.h"
//Print a menu of options to the user.
void PrintMenu()
{
std::cout << "\n(1) Add Account\n";
std::cout << "(2) Delete Account\n";
std::cout << "(3) Print Accounts\n";
std::cout << "(4) Deposit\n";
std::cout << "(5) Withdrawal\n";
std::cout << "(6) Exit\n";
std::cout << "\nEnter selection: ";
}
//Start your main program loop here.
int main()
{
//All class functions are called through a BankingSystem object.
BankingSystem b;
std::cout << "\n*** Welcome to the Banking System ***\n";
PrintMenu();
int selection;
std::cin >> selection;
while ( selection !=6 )
{
switch ( selection )
{
case 1:
&BankingSystem::CreateAccount;
break;
case 2:
&BankingSystem::DeleteAccount;
break;
case 3:
&BankingSystem::PrintAccounts;
break;
case 4:
&BankingSystem::Deposit;
break;
case 5:
&BankingSystem::Withdraw;
break;
default:;
std::cout<< "Incorrect selection.\nPlease enter a number between 1 and 5 or 6 to exit\n";
break;
}
PrintMenu();
}
return 0;
}
Changed the
&BankingSystem::CreateAccount;
to
b.CreateAccount();
now the problem is that when it starts, the first time ok but from the second will always choose the first choice.
Like i open and pressed 1
from now on always will choose 1 when back to menu
And if i put anything beside 1 to 6, it creates another loop
as vlad alluded to, put the input (line 37) just inside the while loop. Also, you probably want to put the PrintMenu function call at the start of the while loop as well, or else it's going to display after you select 6.