Write a program that accepts as input the loan amount, the interest rate per yea
ID: 3626955 • Letter: W
Question
Write a program that accepts as input the loan amount, the interest rate per year, and the monthly payment. (Enter the interest rate as a percentage. For example, if the interest rate is 7.2% per year, then enter 7.2) The program then outputs the number of months it would take to repay the loan. (Note that if the monthly payment is less than the first month's interest, then after each payment, the loan amount will increase. In this case, the program must warn the borrower that the monthly payment is too low, and with this monthly payment, the loan could not be repaid.)Explanation / Answer
please rate - thanks
#include <iostream>
#include <iomanip>
using namespace std;
int main ()
{double loan,rate,payment,monthrate;
int m;
cout<<"How much is the loan: ";
cin>>loan;
cout<<"Enter interest rate: ";
cin>>rate;
monthrate=rate/100./12.;
cout<<"Enter your monthly payment: ";
cin>>payment;
while(payment<=loan*monthrate)
{cout<<"Monthly payment too low. Loan cannot be repaid.";
cout<<"Enter your monthly payment: ";
cin>>payment;
}
m=0;
while(loan>0)
{loan=loan-(payment - (loan * monthrate));
m++;
}
cout<<"At "<<rate<<"% and payments of $"<<payment<<" per month It will take "<< m << " months to repay the loan ";
system("pause");
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.