Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please write C++ Code For the loan assignment: You’ll use the formula of the mon

ID: 3723501 • Letter: P

Question

Please write C++ Code For the loan assignment:

You’ll use the formula of the monthly Payment as follows: monthlyPayment = (loanAmount * annualInterest/12)/(1- 1/pow(1+annualInterest/12,numberOfYears*12)) Then, you can use the following formula to compute Principal, Interest and Balance for the i th month. Balance(0) = Loan Amount; Actual Payment = Monthly Payment + Additional Principal Interest(i) = Balance(i-1) * Annual Interest Rate/12; Principal(i) = Actual Payment – Interest(i) Balance(i) = Balance(i-1) – Principal(i)

When additional principal is greater than 0, it means that the loan will be paid off earlier than the loan term. So, your amortization table should end when the balance becomes zero or negative. So, when the balance is less than the actual payment, the next month’s principal is the same as the previous month’s balance, and it is the end of the amortization table. Your table (program output) needs to follow the exact format as follows. So, you can accommodate a loan amount up to $9,999,999.00. Your program needs to be general enough to handle various user input errors, for example, zero or negative numbers or numbers are too big. Your program requires to be tested against at least 4 cases listed below, and your program should respond correctly and sensibly with proper error messages.

Your program needs to pass the following 4 test cases and deliver desirable results: a. Extreme case 1: loan amount: $10,000,000.00 interest rate: 5.875% term or number of years: 15 Years additional principal the borrower is willing to pay per month: - $2000.00

Explanation / Answer

#include<iostream>
#include<float.h>
#include <iomanip>
#include<limits>
#include<math.h>

using namespace std;


int main(){
float monthlyPayment = 0;
float loanAmount = 0;
float annualInterest = 0;
float addPrincipal = 0;

float balance = 0;
float actPayment = 0;
float principal = 0;
float interest = 0;


unsigned int numberOfYears = 0;


cout<<"Enter loan amount: ";
cin>>loanAmount;
if(loanAmount <= 0){
cout<<"Loan cannot be less then/equal to 0";
return -1;
}
if(loanAmount >= FLT_MAX){
cout<<"Too big a loanAmount, please reconsider";
return -1;
}

cout<<"Enter interest(in %): ";
cin>>annualInterest;
if(annualInterest <= 0){
cout<<"Interest cannot be less then/equal to 0";
return -1;
}
if(annualInterest >= 100){
cout<<"Interest % cannot be equal to/greater than 100";
return -1;
}

cout<<"Enter loan period: ";
cin>>numberOfYears;
if(numberOfYears <= 0){
cout<<"Period of loan cannot be less then/equal to 0";
return -1;
}
if(numberOfYears >= UINT_MAX){
cout<<"Too big a number entered for period";
return -1;
}

cout<<"Enter additional Principal: ";
cin>>addPrincipal;
if(addPrincipal < 0){
cout<<"Period of loan cannot be less then 0";
return -1;
}
if(addPrincipal >= UINT_MAX){
cout<<"Too big a number entered for period";
return -1;
}

monthlyPayment = (float)(double)(loanAmount * annualInterest / 12)/(double)(1 - (1/pow(1+(annualInterest/12),numberOfYears)));
//the original formula was (loanAmount * annualInterest/12)/(1- 1/pow(1+annualInterest/12,numberOfYears*12))
//I changed this too remove the *12 part in the pow function, if the formula was correct then please change it
cout.setf(ios::floatfield,ios::fixed);
cout<<"Monthly Payment is: "<<monthlyPayment<<endl;

cout<<"******Amortization Table*********** ";
cout<<"Year# Total Payment Principal Interest Balance ";

int i = 1;
balance = loanAmount;

do{
cout<<i<<" ";
i++;//for Year Number
cout.setf(ios::floatfield,ios::fixed);
cout.precision(4);

//Update all values
actPayment = monthlyPayment + addPrincipal;
interest = balance * annualInterest / 12;
principal = actPayment - interest;
balance = balance - principal;
if(balance < 0){//If balance has gone down then make it 0
principal = balance + principal;
balance = 0;
}

cout<<setw(8)<<actPayment<<" ";
cout<<setw(8)<<principal<<" ";
cout<<setw(8)<<interest<<" ";
cout<<setw(8)<<balance<<endl;


}while(balance != 0);
return 0;
}

I'm not sure what format you wanted the output to be in, but I hope from this you can make it.