Programming Challenge Chapter 3 – Q #17 Monthly Payments – Tony Gaddis – Starting Out With C++
Problem: -
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
- Add two header file for math and pattern.
- Declare two double variables for input.
- Declare another a int variable for input.
- Declare three double variable for calculations.
- Take input one by one from user.
- Calculate the values.
- Calculate the values by using given formula.
- In last, display output on the screen in a pattern.
- Return 0 to the main function.

 
0 Comments