C++

this program is for my revision purpose..........

Question
Write a C++ program that will allow a consumer to deposit & withdraw funds from their bank accounts (Checking, Saving), check the balance of their bank accounts, choose which account to withdraw from. Choose the amount to withdraw. Show the remaining balance etc. We will assume that the consumer has a checking balance of $3,230.00, and a savings balance of $6,000.00.

I have found the coding, the program is running well for the account type "Checking" savings but if i select option 2 account type which is "saving", it takes the balance as $3230.00. it should take the balance as $6000.00. how to do this in the program.

the code of the program is given below....

#include <iostream>
using namespace std;

int main()

{
int password;

for (int i=0;i<3;i++)

{cout <<"Enter Password:\n";
cin>>password;
system ("color 2"); //changes color so you know that the access to the account is granted
if (password==1)
{cout<<"Access Granted!!!\n";

double balance = 3230;
double savings = 6000;
double withdraw, deposit;
int option;
cout<<"\n";
cout<<" ***WELCOME***\n";
cout<<"*** FNU - Automated Teller Machine***"<<endl;
cout<<"Choose Account Type:\n";
cout<<"\n";
cout<<"[1] Checkings \n"
<<"[2] Savings \n"
<<"\n"
<<"Enter Option:";
cin>>option;

cout<<"Choose a Transaction:\n";
cout<<"\n";
cout<<"[1] Inquire Balance \n"
<<"[2] Withdraw \n"
<<"[3] Deposit \n"
<<"[4] Quit \n"
<<"\n"
<<"Enter Option:";
cin>>option;

switch(option)
{
case 1:
cout<<"\n[[[BALANCE INQUIRY]]]\n";
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
cout<<"\n Your current balance is $"<<balance<<endl;
break;
case 2:
cout<<"\n[[[WITHDRAW]]]\n";
cout<<"Enter amount: $";
cin>>withdraw;

balance = balance - withdraw;

cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);

cout<<"You withdrew $"<<withdraw<<endl;
cout<<"Your remaining balance is $"<<balance<<endl;
continue;
case 3:
cout<<"\n[[[DEPOSIT]]]\n";
cout<<"Enter amount: $";
cin>>deposit;

balance = balance + deposit;

cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);

cout<<"You deposited $"<<deposit<<endl;
cout<<"Your new balance is $"<<balance<<endl;
continue;
case 4:
cout<<"\n***[[[EXIT MODE]]]***\n";

break;


default:
cout<<"\n That is an invalid option \n";
}

break;
}
else


cout<<"Pls try again!!!\n";
}

return 0;
}

closed account (48T7M4Gy)
Does it do what you want it to do?
please put the code inside code tags. it would have been easier to view the code and been able to refer to specific code line number.
check comments below
1
2
3
4
5
cout<<"[1] Checkings \n"
<<"[2] Savings \n"
<<"\n"
<<"Enter Option:";
cin>>option;///notice option here 



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
cout<<"[1] Inquire Balance \n"
<<"[2] Withdraw \n"
<<"[3] Deposit \n"
<<"[4] Quit \n"
<<"\n"
<<"Enter Option:";
cin>>option;///notice same option var is used here. previous option value will be overwritten

switch(option)
{
case 1:
cout<<"\n[[[BALANCE INQUIRY]]]\n";
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
cout<<"\n Your current balance is $"<<balance<<endl;
break;


also, no matter what you write in previous option var, you code only works with 'balance' variable.
1
2
3
4
cout<<"\n Your current balance is $"<<balance<<endl;
...
balance = balance - withdraw;...
balance = balance + withdraw;

note that nowhere did you work with savings.
Topic archived. No new replies allowed.