Hi everyone,
I am stuck in writing Bank Account program. I want that if user wants to create an account, BankAccount class object is created. Then after this i call to its methods such as getBalance() to get the balance in the account. But its not working and I am getting error.
#include <iostream>
#include <string>
class BankAccount
{
protected:
double balance;
public:
BankAccount()
{
balance = 0.0;
}
BankAccount(double b)
{
balance = b;
}
double getBalance()
{
return balance;
}
};
int main()
{
string input;
double bal;
cout <<"Do you want to create an account ??"<<endl;
cin >> input;
if(input == "y")
{
cout <<"\nYour account has been created !"<<endl;
cout <<"Specify your amount to deposite :"<<endl;
cin >> bal;
BankAccount b1(bal);
}
cout <<"Your initial balance is : "<<b1.getBalance() <<"."<<endl; //line of error
return 0;
}
Error is undefined symbol b1. Please help to resolve this error but I need the same logic by asking user to create account in main, Thanks.