In lab lesson 6 part 2 you calculated the present value. In this lab we are goin
ID: 3599670 • Letter: I
Question
In lab lesson 6 part 2 you calculated the present value. In this lab we are going to be calculating the future value. You will need to read in the present value, the monthly interest rate and the number of months for the investment. The formula is going to compute compounded interest (by month). There are a number of required functions that you will be writing, so do not start programming before you have read all of the instructions Here is the formula: F P (1) Where F is the future value, P is the present value, i is the monthly interest rate and t is the number of months. Your program will need to make sure of better variable names that those used above Your program will read the present value, monthly interest rate, and the number of months from cin The output from the program will be written to cout. The numbers read in must be positive values greater than 0 If they are not you need to output the three read in values to cout and display an error message saying the values are not all greater than 0 Note that all double values should be output in fixed format with two digits to the right of the decimal point. This is true for all double output to cout. Also notice that there are no prompts for the input. This is different from other lab lessons you've been doing. When you run the program with your IDE you will not be prompted for the input, you will just have to remember to type it in. Assuming the following input from cin: -10000 48 The following would be written to cout -10000.00 1.10 48 One or more of the above values are not greater than zero If the values are all valid 100 0.99 36Explanation / Answer
#include<iostream>
#include<iomanip>
using namespace std;
bool read_from_cin(double &present_value, double &interest_rate, int &months);
double calculateFutureValue(double presentValue, double interest_rate, int months);
void display(double future_value, double present_value, double interest_rate, int months);
int main()
{
double future_value,present_value, interest_rate;
int months;
if (!read_from_cin(present_value, interest_rate, months))
return -1;
future_value = calculateFutureValue(present_value, interest_rate, months);
display(future_value, present_value, interest_rate, months);
}
bool read_from_cin(double &present_value, double &interest_rate, int &months)
{
cin >> present_value >> interest_rate >> months;
if (present_value < 0 || interest_rate < 0 || months < 0)
{
cout << "One or more of the above values are not greater than zero" << endl;
return false;
}
interest_rate /= 100;
return true;
}
double calculateFutureValue(double presentValue, double interest_rate, int months)
{
double future_value = presentValue*pow((1 + interest_rate), months);
return future_value;
}
void display(double future_value, double present_value, double interest_rate, int months)
{
cout<<fixed;
cout << setprecision(2);
cout << "Future Value " << " Present Value " << "Monthly Interest " << "Months" << endl;
cout << right << setw(15) << future_value << " " << right << setw(10) << present_value << " " << right << setw(6)<<interest_rate * 100 << " " << months << endl;
}
--------------------------------------------------------
//output1
1000
12
48
Future Value Present Value Monthly Interest Months
230390.78 1000.00 12.00 48
-------------------------------
//output2
100
0.99
36
Future Value Present Value Monthly Interest Months
142.57 100.00 0.99 36
//output3
-10000
12
36
One or more of the above values are not greater than zero
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.