fork download
  1. //Cameron Pham CS1A Chapter 6, p. 371, #9
  2. //
  3. /******************************************************************************
  4. * CALCULATE INVESTMENT DEPOSIT
  5. * ______________________________________________________________________________
  6. * This program accepts floating point values for the future value of money
  7. * wanted in an account, the annual interest rate, and number of years planned
  8. * to let money sit in the account. It then calculates the present value
  9. * needed to deposit money today in order to accumulate to the future value.
  10. * ______________________________________________________________________________
  11. * INPUT
  12. * Future value // Amount of money wanted in account
  13. * Annual interest rate // Rate at which interest is accumulated
  14. * Years // Number of years planned to let money sit
  15. *
  16. * OUTPUT
  17. * Present value // Amount of money necessary for deposit
  18. *
  19. *******************************************************************************/
  20. #include <iostream>
  21. #include <cmath> // Required for pow()
  22. using namespace std;
  23.  
  24. float presentValue(float, float, float);
  25.  
  26. int main()
  27. {
  28. float futureVal;
  29. float interestRate;
  30. float numYears;
  31. float presentVal;
  32.  
  33. cout << "Enter the future value you want in your account, annual interest";
  34. cout << " rate, and number of years you plan to let the money sit in the";
  35. cout << " account, and I will tell you the amount that you need to deposit";
  36. cout << " today." << endl;
  37. presentVal = presentValue(futureVal, interestRate, numYears);
  38. cout << "You will have to deposit $" << presentVal << " today." << endl;
  39.  
  40. return 0;
  41. }
  42.  
  43. float presentValue(float futureVal, float interestRate, float numYears)
  44. {
  45. float future;
  46. float rate;
  47. float years;
  48. float present;
  49.  
  50. cin >> future >> rate >> years;
  51.  
  52. present = (future) / pow((1 + rate), years);
  53.  
  54. return present;
  55. }
Success #stdin #stdout 0s 5316KB
stdin
100000 0.10 8
stdout
Enter the future value you want in your account, annual interest rate, and number of years you plan to let the money sit in the account, and I will tell you the amount that you need to deposit today.
You will have to deposit $46650.7 today.