A simple ATM machine program.
Opening balance is 1000.
A minumum balance of 10 is required all the times. If the balance after withdrawal is less than Rm10, do not allow the withdrawal and prompt the user for another amount.
EDIT=The error is that i dont know which strucutre i have to insert for another condition for the minumum balance of 10.
#include<iostream>
#include<cmath>
usingnamespace std;
int main()
{
double opb=1000.00;
char option;
double amount;
cout<<"Your opening balance is RM1000.00"<<endl;
do
{
cout<<"Enter any one of the following options: "<<endl;
cout<<"0.\tQuit"<<endl;
cout<<"1.\tDeposit"<<endl;
cout<<"2.\tWithdrawal"<<endl;
cout<<"3.\tBalance"<<endl;
cout<<"Your option: ";
cin>>option;
if(option!='0' && option!='1' && option!='2' && option!='3')
{
cout<<"Invalid option."<<endl;
cout<<"Please enter again."<<endl;
}
if(option=='0')
{
break;
}
elseif(option=='1')
{
cout<<"Amount to Deposits: RM ";
cin>>amount;
opb+=amount;
}
elseif(option=='2' || opb<10.00)
{
cout<<"Amoun to Withdraw: RM ";
cin>>amount;
opb-=amount;
cout<<"Sorry, a minumum balance of RM10.00 is required."<<endl;
cout<<"Please enter a new amount or 0 to quit."<<endl;
}
elseif(option=='3')
{
cout<<"Your current balance is RM "<<opb<<endl;
}
cout<<"Your current balance is RM "<<opb<<endl;
}while(!(option>='0' && option<='3'));
system("pause");
return 0;
}
expected output:
Your opening balance is RM1000.00
Enter any one of the following options: "<<endl;
0. Quit
1. Deposit
2. Withdrawal
3. Balance
Your option: 2
Amoun to withdraw: 995
Sorry, a minimum balance of 10.00 is required.
Please enter a new amount or 0 to quit.
Amount to withdraw : 950
Your current balance is 50.00
Press any key to continue.....