In: Computer Science
Part 2
Write a C++ program that prompts the user for an Account Number(a whole number). It will then prompt the user for the initial account balance (a double). The user will then enter either w, d, or z to indicate the desire to withdraw an amount from the bank, deposit an amount or end the transactions for that account((accept either uppercase or lowercase). You must use a switch construct to determine the account transaction and a do…while loop to continue processing.
Test Run:
Enter the account number: 1
Enter the initial balance: 5000
SAVINGS ACCOUNT TRANSACTION
(W)ithdrawal
(D)eposit
(Z) to end account transaction
Enter first letter of transaction type (W, D or Z): w
Amount: $1000
Balance for this account is now: $4000.00
SAVINGS ACCOUNT TRANSACTION
(W)ithdrawal
(D)eposit
(Z) to end account transaction
Enter first letter of transaction type (W, D or Z): d
Amount: $500
Balance for this account is now: $4500.00
SAVINGS ACCOUNT TRANSACTION
(W)ithdrawal
(D)eposit
(Z) to end account transaction
Enter first letter of transaction type (W, D or Z): z
No more changes.
Balance for this account is now: $4500.00
Press any key to continue . . .
CODE:
#include<iostream>
using namespace std;
int main()
{
int acc_no;
double inti_bal,withdrawl_amount,deposit;
char choice;
cout<<"Enter the account number:";
cin>>acc_no;
cout<<"Enter the initial balance:";
cin>>inti_bal;
do
{
cout<<"SAVINGS ACCOUNT
TRANSACTION \n(W)ithdrawal\n(D)eposit\n(Z)to end account
transaction\nEnter first letter of transaction type(W,D or
Z):";
cin>>choice;
switch(choice)
{
case 'W':
case 'w' :
cout<<"Amount:$"; cin>>withdrawl_amount;
if(inti_bal>withdrawl_amount)
{
inti_bal=inti_bal-withdrawl_amount;
cout<<"Balance for this
account is now:$"<<inti_bal<<endl;
}
else
{
cout<<"insufficient
balance"<<endl;
};break;
case 'D':
case 'd' :
cout<<"Amount:$"; cin>>deposit;
inti_bal=inti_bal+deposit;cout<<"Balance for this account is
now:$"<<inti_bal<<endl;break;
case 'Z':
case 'z'
:cout<<"No more changes.\nBalance for this account is
now:$"<<inti_bal<<"\n";break;
}
if(choice=='z' ||
choice=='Z')
break;
}while(choice!='z' || choice!='Z');
return 0;
}
OUTPUT:
If you have any doubts please COMMENT...
If you understand the answer please give THUMBS UP...