#include <iostream> #include <iomanip> using namespace std; int main () { int pa
ID: 3673181 • Letter: #
Question
#include <iostream>
#include <iomanip>
using namespace std;
int main ()
{
int pause;
double a; //original loan amount
double r; // annually compounded interest rate, for example 0.08 for 8%
double p; // monthly payment
int m=1; //month number
double x; // remaining balance after m months
cout.setf(ios::fixed);
cout.precision(2);
cout << "Enter loan amount (e.g. 5000.00)" << endl;
cin >> a;
cout << "Enter interest rate (e.g. 0.05 for 5%)" << endl;
cin >> r;
//m_i = r/12;
cout << "Enter monthly payment" << endl;
cin >> p;
r /=12 ; // Determine monthly interest
x=a;
cout << "Month " << "Balance Remaining" << endl;
while (x > 0.0)
{
cout << m << ". " ;
x +=r*x ; // add interest to monthly payment
if(x>p)
{
x -=p;// subtract monthly payment from balance + interest
cout << setw(10) << x << endl;
}
else
{
cout<<"FINAL PAYMENT:"<<x;
x=0;
}
++m; //increment month
}
cin >> pause;
return (0);
}
Now, assume that the user must pay a minimum interest + principle dollar amount each month so that the loan is paid in a finite number of years.
i have the code to start it but couldnt get it to work with the problem stated above.
Explanation / Answer
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main ()
{
int pause;
double a; //original loan amount
double r; // annually compounded interest rate, for example 0.08 for 8%
double p; // monthly payment
int m=1; //month number
double x; // remaining balance after m months
double temp;
double EMI;
int nom;
cout.setf(ios::fixed);
cout.precision(2);
cout << "Enter loan amount (e.g. 5000.00)" << endl;
cin >> a;
cout << "Enter interest rate (e.g. 0.05 for 5%)" << endl;
cin >> r;
cout << "Enter tenure in number of months";
cin >> nom;
r /=12 ; // Determine monthly interest
x=a;
temp = pow((1+r),nom);
EMI = x * r * temp /(temp -1);
p = EMI;
cout<<"EMI = "<<EMI<<endl;
cout << "Month " << "Balance Remaining" << endl;
while (x > 0.0){
cout << m << ". " ;
x +=r*x ; // add interest to monthly payment
if(x>p){
x -=p;// subtract monthly payment from balance + interest
cout << setw(10) << x << endl;
}
else{
cout<<"FINAL PAYMENT:"<<x;
x=0;
}
++m; //increment month
}
cin >> pause;
return (0);
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.