Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Code:
- #include <iostream>
- #include <cmath>
- #include <iomanip>
- using namespace std;
- // function prototype
- bool read(double &, double &, int &);
- double calculateFutureValue(double &, double &, int &);
- void displayValues(double &, double &, int &, double &);
- int main()
- {
- double presentValue, interestRate, futureValue;
- int months;
- bool read_ret_value;
- read_ret_value = read(presentValue, interestRate, months);
- if(read_ret_value){
- interestRate = interestRate/100;
- futureValue = calculateFutureValue(presentValue, interestRate, months);
- interestRate *= 100;
- displayValues(presentValue, interestRate, months, futureValue);
- }
- else{
- cout << endl << "one or more of the above values are not greater than zero";
- }
- return 0;
- }
- bool read(double& presentValue, double& interestRate, int& months)
- {
- cout << endl << "Enter present value, interest rate and number of months? ";
- cin >> presentValue >> interestRate >> months;
- if(presentValue > 0 && interestRate > 0 && months > 0)
- return true;
- else
- return false;
- }
- double calculateFutureValue(double& presentValue, double& interestRate, int& months)
- {
- return presentValue * pow((1 + interestRate), months);
- }
- void displayValues(double& presentValue, double& interestRate, int& months, double& futureValue)
- {
- cout << endl << "Future Value" << setw(20) << "Present Value" << setw(20) << "Monthly Interest" << setw(20) << "Months";
- cout << std::fixed;
- cout << std::setprecision(2);
- cout << endl << futureValue << setw(20) << presentValue << setw(20) << interestRate << setw(20) << months;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement