fork download
  1. //Natalie Zarate CIS5 Chapter 3 P. 146 #17
  2.  
  3. /*******************************************************************************
  4.  *
  5.  * COMPUTE EARNED INTEREST
  6.  * _____________________________________________________________________________
  7.  * This program will accept as input the monthly interest rate, the loan amount,
  8.  * and the number of payments made toward the loan, then computes the monthly
  9.  * payment, how much of the loan was paid off and the amount of interest paid.
  10.  *
  11.  * Computation is based on the formula
  12.  *
  13.  * payment = ((rate * (1 + rate)^N) / ((1 + rate)^(N) - 1)) * L
  14.  *
  15.  * where rate is the monthly interest rate, N is the number of payments, and L
  16.  * is the original loan
  17.  * _____________________________________________________________________________
  18.  * INPUT
  19.  * rate : Monthly interest rate
  20.  * ogLoan : The initial loan amount
  21.  * numPay : Number of payments made on the loan
  22.  *
  23.  * OUTPUT
  24.  * monPay : Monthly payment
  25.  * loanPaid : Amount paid back
  26.  * intrestP : Amount paid in interest
  27.  *
  28.  * ****************************************************************************/
  29. #include <iostream>
  30. #include <iomanip>
  31. #include <cmath>
  32. using namespace std;
  33.  
  34. int main()
  35. {
  36. float rate; // INPUT - Monthly interest rate
  37. float ogLoan; // INPUT - The initial loan amount
  38. float numPay; // INPUT - Number of payments made on the loan
  39. float monPay; // OUTPUT - Monthly payment
  40. float loanPaid; // OUTPUT - Amount of the loan paid off
  41. float interestP; // Output - Amount paid in interest
  42.  
  43. // Promt user for loan amount and display
  44. cout << left << setw(25) << "Loan Amount:";
  45. cin >> ogLoan;
  46. cout << right << "$ " << setprecision(2) << fixed << ogLoan;
  47.  
  48. // Prompt user for monthly interest rate and display
  49. cout << "\n" << left << setw(25) << "Monthly Interest Rate:";
  50. cin >> rate;
  51. cout << right << setw(9) << setprecision(0) << rate << "%" << endl;
  52.  
  53. // Prompt user for number of payments and display
  54. cout << left << setw(25) << "Number of Payments:";
  55. cin >> numPay;
  56. cout << right << setw(10) << setprecision(0) << numPay << endl;
  57.  
  58. // Compute monthly payment
  59. cout << setprecision(2) << fixed;
  60. rate = 0.01;
  61. monPay = 1 + rate;
  62. monPay = rate * pow(monPay, numPay);
  63. monPay = monPay / (pow((rate + 1) , numPay) - 1);
  64. monPay = monPay * ogLoan;
  65.  
  66. // Display monthly payment
  67. cout << left << setw(25) << "Monthly Payment:";
  68. cout << right << "$" << setw(9) << monPay << endl;
  69.  
  70. // Compute amount paid back and display
  71. loanPaid = monPay * numPay;
  72. cout << left << setw(25) << "Amount Paid Back:";
  73. cout << right << "$" << setw(9) << loanPaid << endl;
  74.  
  75. // Compute interest paid and display
  76. interestP = loanPaid - ogLoan;
  77. cout << left << setw(25) << "Interest Paid:";
  78. cout << right << "$" << setw (9) << interestP << endl;
  79.  
  80. return 0;
  81. }
Success #stdin #stdout 0.01s 5284KB
stdin
10000.00
1
36
stdout
Loan Amount:             $ 10000.00
Monthly Interest Rate:           1%
Number of Payments:              36
Monthly Payment:         $   332.14
Amount Paid Back:        $ 11957.16
Interest Paid:           $  1957.16