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";
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;
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
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;