C++, PLEASE WRITE THE CODE AS SIMPLE AS POSSIBLE WITHOUT USING ARRAYS Please wri
ID: 3856118 • Letter: C
Question
C++, PLEASE WRITE THE CODE AS SIMPLE AS POSSIBLE WITHOUT USING ARRAYS
Please write a modular program that calculates the total amount of interest earned for a group of bank accounts. The user should be allowed to specify the number of bank accounts. The amount of interest earned on a single account can be calculated by multiplying the account balance by the percent interest. Use the information in the table below to calculate the interest on an account.
Type of Account
Account Balance
Percent Interest
Checking
< $100
0
Checking
$100 - $1,000
.001
Checking
> $1,000
.002
Savings
<= $100
0
Savings
> $100
.015
Prompt the user for the type of account and the account balance. Use a menu to prompt the user for the type of account rather than letting them type in checking or savings.
Validate the user's input for account balance so that values less than 0 are not accepted.
Calculate the interest earned for each bank account.
Use global constants for the percent interest.
Calculate and display the total amount of interest earned on all the accounts.
Dollar amounts should be properly formatted.
NOTE: Make sure your modular program includes some functions that accept input and return values and don't use arrays.
Type of Account
Account Balance
Percent Interest
Checking
< $100
0
Checking
$100 - $1,000
.001
Checking
> $1,000
.002
Savings
<= $100
0
Savings
> $100
.015
Explanation / Answer
#include <iostream>
using namespace std;
#define PERCENTAGE_0 0
#define PERCENTAGE_001 .001
#define PERCENTAGE_002 .002
#define PERCENTAGE_015 .015
int menu() {
int choice;
cout<<"Enter the account type 1. Checking 2. Savings ";
cin >> choice;
while(choice!=1 && choice!=2) {
cout<<"Invalid Input. ";
cout<<"Enter the account type 1. Checking 2. Savings ";
cin >> choice;
}
return choice;
}
double getInterest(int choice, double balance) {
if(choice == 1) {
if(balance < 100) {
return PERCENTAGE_0;
} else if(balance >=100 && balance <=1000) {
return PERCENTAGE_001;
} else {
return PERCENTAGE_002;
}
} else {
if(balance <= 100) {
return PERCENTAGE_0;
} else {
return PERCENTAGE_015;
}
}
}
int main()
{
int choice = menu();
double balance;
cout<<"Enter the account balance: ";
cin >> balance;
while(balance < 0 ){
cout<<"Invalid Input. ";
cout<<"Enter the account balance: ";
cin >> balance;
}
double interest = getInterest(choice, balance);
double total = balance + balance*interest;
cout<<"Interest: $"<<balance*interest<<endl;
cout<<"Total Amount: $"<<total<<endl;
return 0;
}
Output:
sh-4.2$ g++ -o main *.cpp
sh-4.2$ main
Enter the account type
1. Checking 2. Savings
1
Enter the account balance: 600
Interest: $0.6
Total Amount: $600.6
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.