In: Computer Science
If answer can be shown using a c++ program and leave comments it will be very appreciated!!!
A bank charges $10 per month plus the following check fees for a commercial checking account: $0.10 each for fewer than 20 checks $0.08 each for 20-39 checks $0.06 each for 40-59 checks $0.04 each for 60 or more checks The bank also charges an extra $15.00 if the balance of the account falls below $400 (before any check fees are applied). Write a program that asks for the beginning balance and the number of check written. Compute and display the bank's service fees for the month. Input Validation: Do not accept a negative value for the number of checks written. If a negative value is given for the beginning balance, display an urgent message indicating the account is overdrawn.
Beginning balance: $-100 Number of checks written: 30 Your account is overdrawn! The bank fee this month is $27.40
Beginning balance: $400.00 Number of checks written: -20 Number of checks must be zero or more.
Beginning balance: $300.00 Number of checks written: 36 The bank fee this month is $27.88
Beginning balance: $300.00 Number of checks written: 47 The bank fee this month is $27.82
Beginning balance: $350.00 Number of checks written: 5 The bank fee this month is $25.50
Beginning balance: $300.00 Number of checks written: 70 The bank fee this month is $27.80
If you have any problem with the program feel free to comment
Program
#include <iostream>
#include <stdlib.h>
using namespace std;
float calculateCheckFee(int);
int main(){
float perMonthCharge = 10;
float extraCharge = 15;
float balance, bankFee;
int numberOfChecks;
//taking inputs from user
cout<<"Beginning balance: $";
cin>>balance;
cout<<"Number of checks written: ";
cin>>numberOfChecks;
//checking balance validity
if(balance < 0){
cout<<"Your account is overdrawn!"<<endl;
bankFee = perMonthCharge + extraCharge;
}
else if(balance > 0 && balance < 400){
bankFee = perMonthCharge + extraCharge;
}
else{
bankFee = perMonthCharge;
}
//checking number of checks validity
if(numberOfChecks < 0){
cout<<"Number of checks must be zero or more.";
exit(0) ;
}
bankFee += calculateCheckFee(numberOfChecks);
cout<<"The bank fee this month is $"<<bankFee;
}
//calculating check fee
float calculateCheckFee(int numberOfChecks){
float checkFee;
//getting the check fee according to given range
if(numberOfChecks < 20){
checkFee = 0.10;
}
else if(numberOfChecks>= 20 && numberOfChecks<=
39){
checkFee = 0.08;
}
else if(numberOfChecks>= 40 && numberOfChecks<=
59){
checkFee = 0.06;
}
else{
checkFee = 0.04;
}
return checkFee * numberOfChecks;//calculating total check fee and
returning
}
Output