Hi there,
I am using code blocks and working on bank account programe. I have three classes but just included main function code. My programe works all fine, in which user create account and then deposite initial balance but before end of do while loop, there is getline function to ask user to repeat programe or not. My programe skips that getline function input and continue to rest of programe.
Anybody please help ! and plz tell me why is this happening. I am working on this program from many days.
#include <iostream>
#include <string>
#include "BankAccount.h"
#include "CheckingAccount.h"
#include "SavingsAccount.h"
using namespace std;
int main()
{
string input, acc, repeat;
//string aName; //account name
bool rep = false; //skip the do you want to create acc msg
//boolean check whether an account is created or not.
bool bankA = false;
bool checkingA = false;
bool savingsA = false;
//objects
BankAccount b;
CheckingAccount c;
SavingsAccount s(10.0);
//start of do while loop
start:do{
if(rep == false)
{
cout <<"Do you want to create an account (y/n) ??"<<endl;
getline(cin, input);
}
if(input == "y" || input == "Y")
{
if(acc == "b")
{
bankA = true;
cout << "\nBank Account has been created !\n" <<endl;
b.deposite("Bank Account", true);
//cout <<"repeat value : " <<repeat <<endl;
}
else if(acc == "c")
{
cout << "\nChecking Account has been created !\n" <<endl;
c.deposite("Checking Account", true);
checkingA = true;
}
else if(acc == "s")
{
cout << "\nSavings Account has been created !\n" <<endl;
s.deposite("Savings Account", true);
savingsA = true;
}
else
{
cout <<"\nNo such type of account !\n"<<endl;
}
}
else if(input == "n" || input == "N")
{
break;
}
else
{
cout <<"\nInvalid input !\n"<<endl;
goto start;
}
cout <<"Repeat (y/n) ??"<<endl; //this message is displaying but
getline(cin, repeat); //does not getting input
if(repeat == "y")
rep = true;
}while((input != "y") || repeat == "y");
cout <<"\n\nPrograme is terminated !"<<endl;
return 0;
}