Write a program which asks the user to open a bank account either Current or Savings. Your program will
display the following menu at the start:
Press 1 for Current Account
Press 2 for Savings Account
On the selection of account type, the user will open an account by providing an initial amount. In current account the initial amount for opening an account would be 2000 and for savings it would be 5000. After choosing the account type and opening the account with initial amount, your program will display the following menu:
Press a for Deposit the money
Press b for withdrawing the money
In current account the user cannot withdraw more than 10000 rupees. In Savings account the user cannot withdraw more than 25000. When the user withdraws amount make sure that amount should not be more than the balance in account and at the end of withdrawal transaction, there should be minimum of 500 rupees for each account.
SOLUTION TO THE ABOVE QUESTION
SOLUTION CODE
#include<iostream>
using namespace std;
float area(float,float);
int main()
{
//Menu for the program
cout<<"\nEnter the bank acount you want to open:"<<endl;
cout<<"Press 1 for Current Account"<<endl;
cout<<"Press 2 for Savings Account"<<endl;
int option;
cout<<"Enter your option: ";
cin>>option;
if(option==1)
{
cout<<"\nYou have chosen to create a current account."<<endl;
int initial_amount;
cout<<"Enter an initial amount greater than or equal to 2000: ";
cin>>initial_amount;
cout<<"\nPress a for Deposit the money"<<endl;
cout<<"Press b for withdrawing the money"<<endl;
string my_option;
cout<<"Enter your option: ";
cin>>my_option;
if(my_option=="a")
{
cout<<"Enter the amount you want to deposit: ";
int deposit_amount;
cin>>deposit_amount;
int total_amount = initial_amount + deposit_amount;
cout<<"Dear customer you have successfully deposited "<<deposit_amount
<<" into your savings account your balance is "<<total_amount<<endl;
}
else if(my_option=="b")
{
cout<<"Enter the amount you want to Withdraw: ";
int withdraw_amount;
cin>>withdraw_amount;
int balance = initial_amount - withdraw_amount;
if(withdraw_amount>10000)
{
cout<<"You can not withdraw more than 10000"<<endl;
}
else if(balance<500)
{
cout<<"You should have more than 500 in your account, please try again"<<endl;
}
else
{
cout<<"You have successfully withdrawn "<<withdraw_amount<<" from your current account, your new balance is "<<balance<<endl;
}
}
else
{
cout<<"Invalid option, please try again"<<endl;
}
}
else if(option==2)
{
cout<<"You have chosen to create a savings account."<<endl;
int initial_amount;
cout<<"Enter an initial amount greater than or equal to 5000: ";
cin>>initial_amount;
cout<<"\nPress a for Deposit the money"<<endl;
cout<<"Press b for withdrawing the money"<<endl;
string my_option;
cout<<"Enter your option: ";
cin>>my_option;
if(my_option=="a")
{
cout<<"Enter the amount you want to deposit: ";
int deposit_amount;
cin>>deposit_amount;
int total_amount = initial_amount + deposit_amount;
cout<<"Dear customer you have successfully deposited "<<deposit_amount
<<" into your savings account your balance is "<<total_amount<<endl;
}
else if(my_option=="b")
{
cout<<"Enter the amount you want to Withdraw: ";
int withdraw_amount;
cin>>withdraw_amount;
int balance = initial_amount - withdraw_amount;
if(withdraw_amount>25000)
{
cout<<"You can not withdraw more than 10000"<<endl;
}
else if(balance<500)
{
cout<<"You should have more than 500 in your account, please try again"<<endl;
}
else
{
cout<<"You have successfully withdrawn "<<withdraw_amount<<" from your savings account, your balance is "<<balance<<endl;
}
}
else
{
cout<<"Invalid option, please try again"<<endl;
}
}
else
{
cout<<"You have entered an invalid option please try again"<<endl;
}
}
SAMPLE PROGRAM OUTPUT
Comments
Leave a comment