Hi guys, i am working on a bank program for school but i am running in to a small problem. when the program starts up its displays a menu such as:

item 1
item 2
item 3

And say if you click item 2, it will do waht ever it is supposed to do but when its finished, it wont return back to the menu. (it just closes)

How can i make it so that after i have made my choice, say i withdraw 500$, make it come back to the beginning menu where i can make other choices or withdraw money again etc. I have jsut started learning c++ in school so i am only about 4-5 weeks in.

//BANK ATM PROGRAM.

 


#include <iostream>

using namespace std;

int main ()

{

double pass = 0;
double choice;
int account;
int with;
int bank1 = 500;
int bank2 = 500;
int amount;
int deposit;


cout<<"Please enter you PIN code"<<endl;
cin>>pass;
if (pass == 5555)
cout<<"PIN VALIDATED...."<<endl;

do
{
if (pass != 5555)
{
cout<<"Please enter you PIN Again code"<<endl;
cin>>pass;

}

 

}while( pass != 5555);
system("cls");


while(pass == 5555)
{

	cout<<"PLEASE PICK ONE OF THE BELOW OPTIONS"<<endl;
	
	cout<<"1)DRAW FUNDS"<<endl;
	cout<<"2)DEPOSIT"<<endl;
	cout<<"3)TRANSFER"<<endl;
	cout<<"4)CHECK BALANCE"<<endl;
	cout<<"5)CLOSE"<<endl;
	cin>>choice;


	//WITHDRAW
	 if (choice == 1)
	 {
		 system("cls");
		 cout<<"WHICH ACCOUNT WOULD YOU LIEK TO WITHDRAW FROM"<<endl;
		 cout<<"ACCOUNT ONE"<<endl;
		 cout<<"ACCOUNT TWO"<<endl;
		 cin>>account;
		 //account one

		 if(account == 1)
		 {
			 cout<<"HOW MUCH WOULD YOU LIKE TO WITH DRAW FROM ACCOUNT ONE? YOU HAVE "<< bank1 <<endl;
			 cin>>with;
			 bank1 = bank1 - with;
			 cout<<"YOU WITHDREW " <<with<< " AND HAVE "<<bank1<< " LEFT "<<endl;


		 }
			//account two
		 if(account == 2)
		 {
			 cout<<"HOW MUCH WOULD YOU LIKE TO WITH DRAW FROM ACCOUNT TWO? YOU HAVE "<< bank2 <<endl;
			 cin>>with;
			 bank2 = bank2 - with;
			 cout<<"YOU WITHDREW " <<with<< " AND HAVE "<<bank2<< " LEFT "<<endl;
			 
		 }

	 }

system("pause");
return(0);
}
}

see where it says
cout<<"YOU WITHDREW " <<with<< " AND HAVE "<<bank2<< " LEFT "<<endl;

how can i make it go back to


cout<<"1)DRAW FUNDS"<<endl;
cout<<"2)DEPOSIT"<<endl;
cout<<"3)TRANSFER"<<endl;
cout<<"4)CHECK BALANCE"<<endl;
cout<<"5)CLOSE"<<endl;
cin>>choice;

again to pick other choices. thanks, help would be appreciated.

change this:

system("pause");
return(0);
}
}

to this:

system("pause");
   }
   return 0;
}

Note how consistent indentation helps solve the problem!

Hi, YES thanks so much! that fixed it. Now there is just one problem. Say i want to select the second option in the menu. The user has to press "2" and it should let you deposit money. Now the problem is that when i click 2, nothing happens.

//BANK ATM PROGRAM.

 


#include <iostream>

using namespace std;

int main ()

{

double pass = 0;
double choice;
int account;
int with;
int bank1 = 500;
int bank2 = 500;
int amount;
int deposit;


cout<<"Please enter you PIN code"<<endl;
cin>>pass;
if (pass == 5555)
cout<<"PIN VALIDATED...."<<endl;

do
{
if (pass != 5555)
{
cout<<"Please enter you PIN Again code"<<endl;
cin>>pass;

}

 

}while( pass != 5555);
system("cls");


while(pass == 5555)
{

	cout<<"PLEASE PICK ONE OF THE BELOW OPTIONS"<<endl;
	
	cout<<"1)DRAW FUNDS"<<endl;
	cout<<"2)DEPOSIT"<<endl;
	cout<<"3)TRANSFER"<<endl;
	cout<<"4)CHECK BALANCE"<<endl;
	cout<<"5)CLOSE"<<endl;
	cin>>choice;


	//WITHDRAW
	 if (choice == 1)
	 {
		 system("cls");
		 cout<<"WHICH ACCOUNT WOULD YOU LIEK TO WITHDRAW FROM"<<endl;
		 cout<<"ACCOUNT ONE"<<endl;
		 cout<<"ACCOUNT TWO"<<endl;
		 cin>>account;
		 //account one

		 if(account == 1)
		 {
			 cout<<"HOW MUCH WOULD YOU LIKE TO WITH DRAW FROM ACCOUNT ONE? YOU HAVE "<< bank1 <<endl;
			 cin>>with;
			 bank1 = bank1 - with;
			 cout<<"YOU WITHDREW " <<with<< " AND HAVE "<<bank1<< " LEFT "<<endl;


		 }


			//account two
		 if(account == 2)
		 {
			 cout<<"HOW MUCH WOULD YOU LIKE TO WITH DRAW FROM ACCOUNT TWO? YOU HAVE "<< bank2 <<endl;
			 cin>>with;
			 bank2 = bank2 - with;
			 cout<<"YOU WITHDREW " <<with<< " AND HAVE "<<bank2<< " LEFT "<<endl;
			 
		 }
			
			// DEPOSIT
		 if (choice == 2)
		 {
			 cout<<"PLEASE PICK AN ACCOUNT TO DEPOSIT TO"<<endl;
			 cout<<"ACCOUNT ONE"<<endl;
			 cout<<"ACCOUNT TWO"<<endl;
			 cin>>account;

			 if (account == 1)
				 cout<<"HOW MUCH WOULD YOU LIKE TO DEPOSIT INTO ACCOUNT ONE"<<endl;
					cin>>deposit;
		 }





	 }

 system("pause");
   }
   return 0;
}

// DEPOSIT
if (choice == 2)
{
cout<<"PLEASE PICK AN ACCOUNT TO DEPOSIT TO"<<endl;
cout<<"ACCOUNT ONE"<<endl;
cout<<"ACCOUNT TWO"<<endl;
cin>>account;

if (account == 1)
cout<<"HOW MUCH WOULD YOU LIKE TO DEPOSIT INTO ACCOUNT ONE"<<endl;
cin>>deposit;
}


this part right here wont work, i am using cin>>choice to pick which option the user wold like to go to.

if (choice == 1)
     {
         system("cls");
         cout<<"WHICH ACCOUNT WOULD YOU LIEK TO WITHDRAW FROM"<<endl;
         cout<<"ACCOUNT ONE"<<endl;
         cout<<"ACCOUNT TWO"<<endl;
         cin>>account;
         //account one

         if(account == 1)
         {
             cout<<"HOW MUCH WOULD YOU LIKE TO WITH DRAW FROM ACCOUNT ONE? YOU HAVE "<< bank1 <<endl;
             cin>>with;
             bank1 = bank1 - with;
             cout<<"YOU WITHDREW " <<with<< " AND HAVE "<<bank1<< " LEFT "<<endl;


         }


            //account two
         if(account == 2)
         {
             cout<<"HOW MUCH WOULD YOU LIKE TO WITH DRAW FROM ACCOUNT TWO? YOU HAVE "<< bank2 <<endl;
             cin>>with;
             bank2 = bank2 - with;
             cout<<"YOU WITHDREW " <<with<< " AND HAVE "<<bank2<< " LEFT "<<endl;

         }//this is the end of account 2
    }   // and this is the en of if block of choice
            // DEPOSIT
        else if (choice == 2)
         {
             cout<<"PLEASE PICK AN ACCOUNT TO DEPOSIT TO"<<endl;
             cout<<"ACCOUNT ONE"<<endl;
             cout<<"ACCOUNT TWO"<<endl;
             cin>>account;

             if (account == 1)
                 cout<<"HOW MUCH WOULD YOU LIKE TO DEPOSIT INTO ACCOUNT ONE"<<endl;
                    cin>>deposit;
         }

//account 2
}//end of elseif(choice==2)

you can also use switch statement your code would be much easier then

:)

Edited 3 Years Ago by mike_2000_17: Fixed formatting

This article has been dead for over six months. Start a new discussion instead.