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.
#include<iostream>
usingnamespace 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;
}
}
}
}
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 ...