In: Computer Science
The monthly payment on a loan may be calculated by the following formula:
Payment = Rate * (1 +
Rate)N
((1 + Rate)N -1)
Rate is the monthly interest rate, which is the annual interest rate divided by 12. (12 percent 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 (Input) values then 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
Plz write a program for C++
Source Code:
Output:
Code in text format (See above images of code for indentation):
#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;
/*main function*/
int main()
{
/*variables*/
double Rate,N,L,Payment,total;
/*read loan payment from user*/
cout<<"Enter Loan Amount: ";
cin>>L;
/*read interest rate from user*/
cout<<"Enter Monthly Interest Rate: ";
cin>>Rate;
/*read number of payments from user*/
cout<<"Enter Number of Payments: ";
cin>>N;
Rate=Rate/100;
/*calculate monthly payment*/
Payment=L*((Rate*(pow(1+Rate,N)))/(pow(1+Rate,N)-1));
/*total amount to be paid*/
total=Payment*N;
cout<<fixed<<setprecision(2)<<endl;
/*print report*/
cout<<"Loan
Payment:\t$"<<L<<endl;
cout<<"Monthly Interest
Rate:\t"<<Rate*100<<"%"<<endl;
cout<<"Number of
Payements:\t"<<N<<endl;
cout<<"Monthly Payment:\t$
"<<Payment<<endl;
cout<<"Amount Paid Back:\t$
"<<total<<endl;
/*calculate interest and print*/
L=total-L;
cout<<"Interest Paid:\t$ "<<L;
return 0;
}