atm program

In this program when the loop is repeated the balance inquiry gives the standard balance.Not the value after withdrawal. similarly when cash is deposited it gives it again gives the standard value. How to correct this and when the loop is repeated it gives the new value after deposit or withdrawal.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
 #include<iostream>
using namespace std;

int main()
{
	int a;
	cout<<"Welcome To Automated Teller Machine!"<<endl;
		for(int i=0;i<3;i++)
{
	cout<<"Please enter your 4 digit password=";
	cin>>a;
		if(a!=1234 && i<2)
		{  
			   cout<<"Wrong Password!"<<endl;
			   cout<<"Try again!"<<endl;
        }
        for(int j=0;j<3;j++)
        {
        	if(a!=1234 && i==2)
        	{
        		{
				     cout<<"Three times wrong Password!"<<endl;
				     cout<<"Your access has been terminated!"<<endl;
				     break;
			        } 
			}
		}
		if (a==1234)
		{
			break;
		}
}
         
       	if(a==1234)
       	
       	{
			   	int b;
       	
       		
			   
       		 cout<<"Welcome!"<<endl<<endl;
       		 cout<<"What do you want to do?"<<endl;
       		 cout<<"1.Check current balance."<<endl;
       		 cout<<"2.Cash Withdrawal."<<endl;
       		 cout<<"3.Cash Deposit."<<endl;
       		 cout<<"4.Quit."<<endl<<endl;
       		 cout<<"Enter=";
       		cin>>b;
       		cout<<endl<<endl;
       	while(b!=0)
       	{
       		
       		int d,e,g;
       		
       		 
       		 switch(b)
       		    {
       			   case 1:
       			    	{
       			    		
       					   cout<<"Your current balance is=$"<<10000;
       					   break;
					     }
				    case 2:
				        {
				        	cout<<"Your current balance is=$"<<10000<<endl<<endl;
				     	   int d;
				     	   
				     	   cout<<"Please enter the amount you want to withdraw=$";
				     	   cin>>d;
				     	   
				     	   cout<<endl;
				     	  if(d>10000)
				     	  {
				     	  	cout<<"You don't have enough cash.";
						   }
						   
						   else
						   {
						   	cout<<"Take cash from the below slot."<<endl;
						   	cout<<"Your cash left after withdrawal is=$"<<10000-d;
						   }
						   break;
						   
					    }
					   
						case 3:
						{
							int e;
						    
							cout<<"How much amount you wnat to deposit?"<<endl<<endl;
							cout<<"Enter=$";
							cin>>e;
							
							cout<<"Your total amount after deposit is=$"<<10000+e;
							break;
						}
					
						case 4:
						{
							cout<<"Thank you for using the ATM."<<endl;
							cout<<"Bye.";
							break;
							
							   }	   
			    }
			    if(b==4)
			    {
			    	break;
				}
			    cout<<endl<<endl;
			    int f;
			    cout<<"Want to again do something again?(1/0)=";
			    cin>>f;
			    if(f==1)
			    {
			    	 cout<<"1.Check current balance."<<endl;
       		 cout<<"2.Cash Withdrawal."<<endl;
       		 cout<<"3.Cash Deposit."<<endl;
       		 cout<<"4.Quit."<<endl<<endl;
       		 cout<<"Enter=";
			    	
			    	cin>>b;
			    
			    	
			    	
			    	if(b==4)
			    	{
			    		cout<<"Thank you."<<endl<<"Bye.";
			    		break;
					}
			    
			    	
				}
				else
				{
					break;
					b==0;
				}
			    
            }
       		
	}

}
please help
I like it, I want to use YOUR ATM!

it looks like you compute the start balance +- the withdraw/deposit value but never update the start value, so it remains the same forever. You must update the current balance each time you withdraw or deposit.

That is, that 10000 value should be in a variable.
so
int balance = 10000;

...
case withdraw
if(has enough)
balance -= amount;
case deposit
balance += amount;
...

for all cases //abstract this out of each case, do it for all actions maybe??
cout current balance is ...





Last edited on
Topic archived. No new replies allowed.