Hello Guys,
I create a small program than allows user to create bank account and add or get money
but now i want to edit my code to accept more than one account
how can i do it ?
#include "header.h"
Account::Account(){
int i=0;
cout << "To create account enter 1\nTo exit enter any button else : ";
cin >> i;
if (i==1)
create();
}
void Account::set(string n,int x,int y=0){
name =n;
balance=x;
password =y;
}
string Account::getName(){
return name;
}
int Account::getBalance(){
return balance;
}
int Account::getPassword(){
return password;
}
void Account::print(){
cout<<"your balance is "<<getBalance()<<endl;
}
void Account::withdraw(){
int Getfrom;
cout << "Enter how much you need : \n";
cin >> Getfrom;
if (balance >= Getfrom) { balance = balance - Getfrom ; }
else cout << "You don't have enough balance\n";
print();
}
void Account::deposit(){
int addto;
cout << "Enter how much you want to add : \n";
cin >> addto;
balance +=addto;
print();
}
int Account::userStartup(){
string n;
int y ;
int compar;
cout<<"Enter your name "<<endl;
cin >>n;
if (n=="-1"){return 0;}
cout<<"enter your password"<<endl;
cin>>y;
if( n == getName() and y == getPassword() ) {user();}
else { cout<<"one of the name or the password is wrong"<<endl;
userStartup(); }
}
void Account::create(){
string n;
int x=0;
int y=0;
cout << "Enter your name : "<<endl ;
cin >>n;
cout << "Enter your balance : "<<endl;
cin >> x;
cout << "Enter your Password : "<<endl;
cin >>y;
set(n,x,y);
cout <<"Congratulations "<<endl;//<<password;
startup();
}
void Account::startup(){
int x=0;
cout <<"enter 1 to add or deposit \nenter any other button to exit : "<<endl ;
cin >> x;
if (x==1) userStartup();
}
int Account::user(){
int choice;
cout << "\nTo get money enter 1";
cout << "\nTo add money enter 2 \nTo Show your balance enter 3\n enter any button else to exit "<<endl;
cin >> choice;
if (choice == 1) { withdraw(); user(); }
else if (choice == 2 ) { deposit(); user(); }
else if (choice == 3 ) { print(); user(); }
else {cout<< "See you later\n\n"; return 0; }
}
nothing in main function, i just create an object on it