I need help with this question 19.) Modify the program to allow the user to ente
ID: 3688051 • Letter: I
Question
I need help with this question
19.) Modify the program to allow the user to enter the minimum and maximum interest rates, as shown in Figure 10-27. Also
change the getBalance function to a void function. Test the program appropriately. Here is the code:
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
//function prototype
double getBalance(int amount, double rate, int y);
int main()
{
int deposit = 0;
double interestRate = 0.0;
double acctBalance = 0.0;
cout << "Deposit: ";
cin >> deposit;
cout << "Rate (in decimal form): ";
cin >> interestRate;
cout << fixed << setprecision(2);
for (int year = 1; year < 4; year += 1)
{
acctBalance =
getBalance(deposit, interestRate, year);
cout << "Year " << year << ": $"
<< acctBalance << endl;
} //end for
return 0;
} //end of main function
//*****function definitions*****
double getBalance(int amount, double rate, int y)
{
double balance = 0.0;
balance = amount * pow((1 + rate), y);
return balance;
} //end of getBalance function
Thank you. I have a test tomorrow and want to ensure I have the correct answer.
Explanation / Answer
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
double balance = 0.0;
//function prototype
void getBalance(int amount, double rate, int y);
int main()
{
int deposit = 0;
double interestRate = 0.0;
double acctBalance = 0.0;
double maxinterestRate;
double mininterestRate;
cout << "Deposit: ";
cin >> deposit;
cout << "Rate (in decimal form): ";
cin >> interestRate;
cout << "The minimum intrestRate : ";
cin >> mininterestRate;
cout << "The maximum intrestRate : ";
cin >> maxinterestRate;
if(mininterestRate>=interestRate && maxinterestRate<=interestRate )
{
cout << fixed << setprecision(2);
for (int year = 1; year < 4; year += 1)
{
getBalance(deposit, interestRate, year);
acctBalance = balance;
cout << "Year " << year << ": $"
<< acctBalance << endl;
} //end for
return 0;
}
else
{
cout << "Intersent rate is beyond your expectations ";
}
} //end of main function
//*****function definitions*****
void getBalance(int amount, double rate, int y)
{
balance = amount * pow((1 + rate), y);
} //end of getBalance function