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"

int i=0;
cout << "To create account enter 1\nTo exit enter any button else : ";
  cin >> i;
   if (i==1)
void Account::set(string n,int x,int y=0){
    name =n;
    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";

void Account::deposit(){
    int addto;
    cout << "Enter how much you want to add : \n";
cin >> addto;
    balance +=addto;

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;

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;
cout <<"Congratulations "<<endl;//<<password;
   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

2 Years
Discussion Span
Last Post by ddanbe

Your code above defines the Account object.

if you want to create one of these, here is how you can create one.

Account firstAccount;

If you want to create another one:

Account anotherAccount;

How about if you want to create a third?

Account thirdAccount;

If you want lots of Account objects, just create lots.

Edited by Moschops


But in this case user won't be able to access the account that he want.
I mean if he creates third account, he can't go back to first account ( to add or get )

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.