C++ please o AT&T; LTE 8:00 PM mail-attachment.googleusercontent.com upon the pr
ID: 3587908 • Letter: C
Question
C++ please o AT&T; LTE 8:00 PM mail-attachment.googleusercontent.com upon the principle, an annual interest rate of either 5.75% or 3.5%, and time. You must use an if-else statement. Specifications: The program should prompt the user for the principle and the time, and ask the user which interest rate to use (1 for 5.75%, 2 for 3.5%). Use "Enter principle : as the prompt for the principle"-Enter time (in days) : as the prompt for the time, and-Enter interest rate (1 for high rate, 2 for low rate): as the prompt for the interest rate. If the user does not enter a correct number, print an error message that states "Invalid Interest Rate ” The interest and principle should be declared as floating point variables, and the two interest rates should be defined as constants. The time should be declared as an integer, as well as a new variable used to store the choice for which interest rate to use. The variable used to store the years should still be a floating point value. Once you read in the information, print results of the calculation from days to years, in addition to the interest, both using a-%.2f" format. Please use the following variable names: interest- stores the earned interestI (floating point principle - stores the initial principle P (loating point) RATE HIGH-Stores the high interest rate r (5.75%) (constant) RATELow stores the low interest rate r (3.596) (constant) time - stores the time in days (integer) years stores the time in years floating point) choice -stores the choice of your interest rate (integer) - If you execute the program with the following underlined inputs, the results will be: Enter principle: 4500.00 Enter time (in days): 300 Enter interest rate (1 for high rate, 2 for low rate): Invalid Interest Rate Enter principle: 4500.00 Enter time (in days): 300 Enter interest rate (1 for high rate, 2 for low rate) 2 In 0.82 years, the simple interest earned is: $129.45Explanation / Answer
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int time;
float years;
float RATE_HIGH = 5.75;
float RATE_LOW = 3.5;
float principle;
float interest;
cout << "Enter principle: ";
cin >> principle;;
cout << "Enter time (in days): ";
cin >> time;
years = time/365.0;
cout << "Enter interest rate (1 for high rate, 2 for low rate): ";
int choice;
cin >> choice;
cout << fixed;
cout << setprecision(2);
switch (choice) {
case 1:
interest = principle*years*RATE_HIGH/100;
cout << "In " << years << " years, the simple interest earned is: $" << interest << endl;
break;
case 2:
interest = principle*years*RATE_LOW/100;
cout << "In " << years << " years, the simple interest earned is: $" << interest << endl;
break;
default:
cout << "Invalid interest rate";
}
return 0;
}
Sample run
Enter principle: 4500.00
Enter time (in days): 300
Enter interest rate (1 for high rate, 2 for low rate): 2
In 0.82 years, the simple interest earned is: $129.45
Enter principle: 4500.00
Enter time (in days): 300
Enter interest rate (1 for high rate, 2 for low rate): x
Invalid interest rate
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.