Programming Challenge Chapter 3 – Q #17 Monthly Payments – Tony Gaddis – Starting Out With C++

Programming Challenge Chapter 3 – Q #17 Monthly Payments – Tony Gaddis – Starting Out With C++








Problem: -

The monthly payment on a loan may be calculated by the following formula:
Rate is the monthly interest rate, which is the annual interest rate divided by 12. (12% annual interest would be 1 percent monthly interest.) N is the number of payments and L is the amount of the loan. Write a program that asks for these values and displays a report similar to

                           Loan Amount:                 $ 10000.00
                          Monthly Interest Rate:                  1%
                          Number of Payments:                   36
                          Monthly Payment:               $ 332.14
                          Amount Paid Back:          $ 11957.15
                          Interest Paid:                      $ 1957.15

Solution: -

#include <iostream>

#include <iomanip>

#include <cmath>

using namespace std;

int main()

{

      double rate, L;

      int N;

      double payment = 0.0, ammount_paid_back = 0.0, intrest_paid = 0.0;

     cout << "Enter Loan Ammount:  ";

      cin >> L;

      cout << "Enter Number Of Payments : ";

      cin >> N;

      cout << "Enter Annual Intrest Rate: ";

      cin >> rate;

      //Calculation

      rate = (rate / 12)/100.0;

      payment = (rate * (pow(1 + rate, N)) / (pow(1 + rate, N) - 1)) * L;

      ammount_paid_back = payment * N;

      intrest_paid = ammount_paid_back - L;

      cout << setprecision(2) << showpoint << fixed;

      cout << "Loan Ammount:          $" << setw(8) << L << endl;

      cout << "Monthly Intrest Rate:   " << setw(8) << rate * 100 << endl;

      cout << "No of Payments:         " << setw(8) << N << endl;

      cout << "Monthl Payment:        $" << setw(8) << payment << endl;

      cout << "Ammmount Paid Back:    $" << setw(8) << ammount_paid_back << endl;

      cout << "Intrest Paid:          $" << setw(8) << intrest_paid << endl;

      return 0;

}

This is the solution of this question




OUTPUT OF THIS QUESTION 

Input is highlighted with yellow color.


Explanation of this Solution

  1. Add two header file for math and pattern.
  2. Declare two double variables for input.
  3. Declare another a int variable for input.
  4. Declare three double variable for calculations.
  5. Take input one by one from user.
  6. Calculate the values.
  7. Calculate the values by using given formula.
  8.  In last, display output on the screen in a pattern.
  9. Return 0 to the main function.

Also, I attach CPP file of this problem. You can download this file

Click Here to Download This File


Post a Comment

0 Comments