Question
Please take the followingC++ code and do the following: first tell the user the minimum monthly payment and then prompting the user to enter the
Please take the followingC++ code and do the following:
first tell the user the minimum monthly payment and then prompting the user to enter the monthly payment.
Your last payment might be more than the remaining loan amount and interest on it. In this case, output the actual amount of the last payment. Also, output the total interest paid.
#include
#include
using namespace std;
int main ()
{
double loanAmount;
double interestRate;
double interestRatePerMonth;
double monthlyPayment;
double paymentPrincipal;
int months;
cout << fixed << showpoint;
cout << setprecision(2);
cout << "Enter the loan amount: ";
cin >> loanAmount;
cout << endl;
cout << "Enter the interest rate per year: ";
cin >> interestRate;
cout << endl;
interestRatePerMonth = (interestRate / 100) / 12;
cout << "Enter the monthly payment: ";
cin >> monthlyPayment;
if (monthlyPayment <= loanAmount * interestRatePerMonth)
{
cout << "Monthly payment is too low. The loan cannot be repaid."
<< endl;
return 1;
}
months = 0;
while (loanAmount > 0)
{
paymentPrincipal = monthlyPayment - (loanAmount * interestRatePerMonth);
loanAmount = loanAmount - paymentPrincipal;
months++;
}
cout << "It will take " << months << " months to repay the loan."
<< endl;
return 0;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started