• 0

[c++]Need help with ATM bank program and menu.


Question

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.

Link to comment
Share on other sites

10 answers to this question

Recommended Posts

  • 0

Hi, ya i got that fixed but now i have another 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 &lt;iostream&gt;

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&lt;&lt;"Please enter you PIN code"&lt;&lt;endl;
cin&gt;&gt;pass;
if (pass == 5555)
cout&lt;&lt;"PIN VALIDATED...."&lt;&lt;endl;

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

}



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


while(pass == 5555)
{

	cout&lt;&lt;"PLEASE PICK ONE OF THE BELOW OPTIONS"&lt;&lt;endl;

	cout&lt;&lt;"1)DRAW FUNDS"&lt;&lt;endl;
	cout&lt;&lt;"2)DEPOSIT"&lt;&lt;endl;
	cout&lt;&lt;"3)TRANSFER"&lt;&lt;endl;
	cout&lt;&lt;"4)CHECK BALANCE"&lt;&lt;endl;
	cout&lt;&lt;"5)CLOSE"&lt;&lt;endl;
	cin&gt;&gt;choice;


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

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


		 }


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

		 }

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

			 if (account == 1)
				 cout&lt;&lt;"HOW MUCH WOULD YOU LIKE TO DEPOSIT INTO ACCOUNT ONE"&lt;&lt;endl;
					cin&gt;&gt;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.

Link to comment
Share on other sites

  • 0

move if(choice==2) outside of if(choice==1)

for your information,

if statements require brackets if the code is longer then 2 statements.

Link to comment
Share on other sites

  • 0

it would be much better if you start using seperate methods for the different functions in your program.. at the moment with everything written inside of the main method you can only go thru the program once.. but with seperate methods you can call a method eg. 'withdraw' multiple times without having to rewrite the code or without restarting the program..

Link to comment
Share on other sites

  • 0
move if(choice==2) outside of if(choice==1)

for your information,

if statements require brackets if the code is longer then 2 statements.

Is it more than two statements? I always thought that if your IF was more than 1 line (1 statement) you needed braces because the scope of the IF is only that line. I tend to use braces anyway, same goes for FOR loops.

it would be much better if you start using seperate methods for the different functions in your program.. at the moment with everything written inside of the main method you can only go thru the program once.. but with seperate methods you can call a method eg. 'withdraw' multiple times without having to rewrite the code or without restarting the program..

Yeah that's a good idea although it could be added quite easily once the program is up and running. Agreed on the saved codespace too. Depending on the task/project you could also add quite a bit to it like storage of funds, account details etc

Link to comment
Share on other sites

  • 0
Is it more than two statements? I always thought that if your IF was more than 1 line (1 statement) you needed braces because the scope of the IF is only that line. I tend to use braces anyway, same goes for FOR loops.

Yeah that's a good idea although it could be added quite easily once the program is up and running. Agreed on the saved codespace too. Depending on the task/project you could also add quite a bit to it like storage of funds, account details etc

yeh if the if statement is more than one line of code you need parenthese eg.

if ( i < 5 )

{

i++

cout << i << endl;

}

also it would be much better to code the program correctly the first time round rather than have to re-code it.. the comments within the code need to be better written and explain what's going on more aswell so it'll make it easier for people to understand your coding..

Link to comment
Share on other sites

  • 0
gee my english is getting poorer at the minute!

i did mean >= 2 statements

maybe ill just stop saying stuff lol

Have you thought of using a switch statement instead of an if statement?

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.