(Financial application: compare loans with various interest rates) Write a program that lets the user enter the loan amount and loan period in number of years and displays the monthly and total payments for each interest rate starting from 5% to 8% with an increment of 1/8

Respuesta :

Answer:

// Program is written in C++ programming language

// Comments are used for explanatory purpose

// Program starts here

#include <iostream>

#include <cmath>

using namespace std;

int main ()

{

// Variable Declarations

int years; double amount;

// Get input for loan amount and period (in years)

cout<<"Loan Amount: ";

cin>>amount;

cout<<"Number of Years: ";

cin>>years;

// Display table header

cout<<"Interest Rate Monthly Payment Total Payment";

// Calculate and display interest rates

// Start iteration

for (double i = 5.0; i <= 8; i += 0.125) {

cout<<i;

// Calculate Monthly Interest Rate

double monthlyRate = i / 1200;

// Calculate and Print Monthly Payment

double monthlyPay = amount * monthlyRate / (1 - 1 / pow(1 + monthlyRate, years * 12)); cout<<monthlyPay; cout<<"\n"<<(monthlyPay * 12) * years);

}

return 0;

}

// End of program