Can anyone help me to write C++ program for this question Interest on a loan is
ID: 3882499 • Letter: C
Question
Can anyone help me to write C++ program for this question
Interest on a loan is paid on a declining balance, and hence a loan with an interest rate of, say, 14% can cost significantly less than 14% of the balance. Write a program that takes a loan amount and interest rate as input and then outputs the monthly payments and balance of the loan until the loan is paid off. Assume that the monthly payments are one-twentieth of the original loan amount, and that any amount in excess of the interest is credited toward decreasing the balance due. Thus, on a loan of $20,000, the payments would be $1,000 a month. If the interest rate is 10%, then each month the interest is one-twelfth of 10% of the remaining balance. The first month, (10% of $20,000)/12, or $166.67, would be paid in interest, and the remaining $833.33 would decrease the balance to $19,166.67. The following month the interest would be (10% of $19,166.67)/12, and so forth. Also have the program output the total interest paid over the life of the loan. Finally, determine what simple annualized percentage of the original loan balance was paid in interest. For example, if $1,000 was paid in interest on a $10,000 loan and it took two years to pay off, then the annualized interest is $500, which is 5% of the $10,000 loan amount. Your program should allow the user to repeat this calculation as often as desired.Explanation / Answer
#include <iostream>
using namespace std;
int main() {
//Declaring the variables. We will expalin the variables when we mention them
float loanAmount, installmentAmount, balanceAmount, interestForMonth, totalInterest,
simpleInterestRate, interestRate;
int installment;
char answer='y';
do{
//clearing cin so that the old inputs do not get entered in loan Amount
cin.clear();
cout<<" Enter the loan amount: ";
//loanAmount contains the amount of loan
cin >> loanAmount;
do{
//clearing cin so that the old inputs do not get entered in inetrest rate
cin.clear();
cout<<" Enter the interest rate: ";
//interestRate is the rate of interest
cin >> interestRate;
/*if interest Rate is equal to 60, the monthly interest becomes same as the installment.
Hence there will be no decrease in Balance Amount.
So we use the do while loop to ensure interest rate is less than 60*/
if(interestRate>60){
cout<<"Interest Rate more than 60 will lead to infinite installments/n";
}
}while(interestRate>=60);
//installement amount is the monthly installment which is 1/20th of original loan amount
installmentAmount=loanAmount/20;
//balance amount will contain the remaining amount to be paid. We initialize it to loan amount
balanceAmount=loanAmount;
//installments will be the current monthly installment being paid
installment=1;
//total interest is the interest getting added to the balance every month. We initialize it to 0
totalInterest=0.0;
//Starting with the 1st installment and countinuing till balance is not 0 using do while loop
cout<<" The payment structure is: ";
do{
/*Checking if balance amount is more than installment amount. If it is less,
then it will be the last installment and the amount to be paid will be the balance remaining*/
if(balanceAmount>installmentAmount){
//monthly interest to be added is 1/12th of the annual interest rate of the balance amount
interestForMonth=(1.0/12.0)*(float(interestRate)/100)*balanceAmount;
//balance is reduced by the amount of monthly installment
balanceAmount=balanceAmount-(installmentAmount-interestForMonth);
//printing the current intallment details
cout<<" Month: "<<installment<<" Payment Amount: "<<installmentAmount
<<" InterestAdded: "<<interestForMonth<<" Balance Amount: "<<balanceAmount;
//We increment the installment number for the next month.
installment++;
}
else{
/*This else block will be used when balance amount is less than equal to intallment amount.
Hence this is the last installment. Our intallment amount will be the remaining balance.
No interest will be added and we do not need to increment the installment. */
installmentAmount=balanceAmount;
interestForMonth=0;
balanceAmount=0;
//printing the final installment details
cout<<" Month: "<<installment<<" Payment Amount: "<<installmentAmount
<<" InterestAdded: "<<interestForMonth<<" Balance Amount: "<<balanceAmount;
}
//Incrementing the total interest by the interest generated for the current month
totalInterest+=interestForMonth;
}while(balanceAmount!=0);
cout<<" Loan Payment Completed";
//Calculating Simple interest as the % of loan amount that was paid as interest per year
simpleInterestRate=(totalInterest/loanAmount)*(12.0/installment)*100.0;
cout<<" Interest Paid: "<<totalInterest<<" Installments: "<<installment<<" Simple Interest: "<<simpleInterestRate<<"%";
cout<<" Do you want to continue(Press y for yes, any other key to exit): ";
//Clearing cin and checking if user wants to continue
cin.clear();
cin>>answer;
}while(answer=='y');
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.