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

Code in C++(3-5) Other requirements (From class) -No global variables may be use

ID: 3841767 • Letter: C

Question

Code in C++(3-5)

Other requirements (From class)

-No global variables may be used

-While variables may not be global, all functions and constants should be declared global.

-all assignments must contain functions, even if it is possible to do without one.

-If the assignment calls for just a function, you must code a driver to test the function. The driver and the function both must be submitted.

5. Interest on a loan is paid on a declining balance, and hence a loan with an interest rate of, say, 14 percent can cost significantly less than 14 percent 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 percent, then each month the interest is one-twelfth of 10 percent of the remaining balance. The first month, (10 percent of $20,000) 12, or 166.67, would be paid in interest, and the remaining $833.33 would de- crease the balance to $19,166.67. The following month the interest would be (10 percent 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 2 years to pay off, then the annualized interest is $500, which is 5 percent of the $10,000 loan amount. Your program should allow the user to repeat this calculation as often as desired

Explanation / Answer

PROGRAM CODE:

#include <iostream>
using namespace std;

void calculateInterest(double loanAmount, double interestRate)
{
   cout<<" Month Balance ";  
   double balance = loanAmount;
   double amount = loanAmount/20;
   double totalInterest = 0;
   int i=0;
   while(balance>0)
   {
       double interest = balance/(interestRate*12);
       totalInterest += interest;
       if(amount - interest > balance)
       balance = 0;
       else
       balance -= (amount - interest);
       i++;
       cout<<i<<" "<<balance<<endl;
   }
   cout<<"Total interest: "<<totalInterest<<endl;
   double monthlyInterest = totalInterest/i;
   cout<<"Annual Interest: "<<(monthlyInterest*12)<<endl;
}

int main() {
   while(true)
   {
       double amount, interest;
       cout<<"Enter the loan amount (-1 to quit): ";
       cin>>amount;
       if(amount == -1)
           exit(0);
       cout<<"Enter the interest: ";
       cin>>interest;
       calculateInterest(amount, interest);
   }
  
   return 0;
}

OUTPUT: