Advertisement
Guest User

Untitled

a guest
Apr 21st, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. Code:
  2. #include <iostream>
  3. #include <cmath>
  4. #include <iomanip>
  5. using namespace std;
  6.  
  7. // function prototype
  8. bool read(double &, double &, int &);
  9. double calculateFutureValue(double &, double &, int &);
  10. void displayValues(double &, double &, int &, double &);
  11.  
  12. int main()
  13. {
  14. double presentValue, interestRate, futureValue;
  15. int months;
  16. bool read_ret_value;
  17.  
  18. read_ret_value = read(presentValue, interestRate, months);
  19. if(read_ret_value){
  20. interestRate = interestRate/100;
  21. futureValue = calculateFutureValue(presentValue, interestRate, months);
  22. interestRate *= 100;
  23. displayValues(presentValue, interestRate, months, futureValue);
  24. }
  25. else{
  26. cout << endl << "one or more of the above values are not greater than zero";
  27. }
  28.  
  29. return 0;
  30. }
  31.  
  32. bool read(double& presentValue, double& interestRate, int& months)
  33. {
  34. cout << endl << "Enter present value, interest rate and number of months? ";
  35. cin >> presentValue >> interestRate >> months;
  36.  
  37. if(presentValue > 0 && interestRate > 0 && months > 0)
  38. return true;
  39. else
  40. return false;
  41. }
  42.  
  43. double calculateFutureValue(double& presentValue, double& interestRate, int& months)
  44. {
  45. return presentValue * pow((1 + interestRate), months);
  46. }
  47.  
  48. void displayValues(double& presentValue, double& interestRate, int& months, double& futureValue)
  49. {
  50. cout << endl << "Future Value" << setw(20) << "Present Value" << setw(20) << "Monthly Interest" << setw(20) << "Months";
  51. cout << std::fixed;
  52. cout << std::setprecision(2);
  53. cout << endl << futureValue << setw(20) << presentValue << setw(20) << interestRate << setw(20) << months;
  54.  
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement