In: Computer Science
Use coding langues C ++
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 will ask the user to enter these value and then displays a report that shows:
Format your dollar amount in fixed-point notation, with two decimal places of precision.
// PLEASE LIKE THE SOLUTION
// FEEL FREE TO DISCUSS IN COMMENT SECTION
// C++ PROGRAM
#include<bits/stdc++.h>
using namespace std;
// main function
int main(){
// loan amount
double loanAmount;
double rate;
int N; // number of payments
// ask user for details
cout<<"Enter the loan amount: ";
cin>>loanAmount;
cout<<"Enter the rate in %: ";
cin>>rate;
rate = rate/100;
cout<<"Enter number of Payments: ";
cin>>N;
// variables
double monthlyPayment;
double AmountPaid;
//
monthlyPayment =
((rate*(pow(rate+1,N)))/((pow(rate+1,N))-1))*loanAmount;
// amount paid back
AmountPaid = monthlyPayment*N;
// print by proper formatting
cout << "Loan
amount
$"
<<setprecision(2)<<fixed<<loanAmount<<endl;
cout<<"Monthly Interest Rate
"<<rate*100 <<"%"<<endl;
cout << "Number of
Payments "<< N <<
endl;
cout << "Monthly
Payment $"
<<setprecision(2)<<monthlyPayment<<endl;
cout << "Amount Paid
Back $"
<<setprecision(2)<<AmountPaid<<endl;
cout << "Interest
Paid $"
<<setprecision(2)<<(AmountPaid-loanAmount)<<endl;
return 0;
}
// SAMPLE OUTPUT