user need to enter loan amount and periods number of years.The interest is fixed 5% to 8% , with an increment of 1/8. for loop, c++.
i have write the program but something wrong on it.
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main()
{
double interestRate;
double loanAmount;
double numberOfYears;
double monthlyPayment;
double totalPayment;
cout <<" Interest rate Monthly Payment Total payment\n";
//Display the table body
for (int interestRate = 5.0 ; interestRate <= 8.0 ; interestRate+=0.125)
cout << setw(3) << fixed << interestRate;
cin >> interestRate;
cout<<" \n";
// Prompt user to enter loan amount
cout <<" Enter loan amount : " << endl;
cin >> loanAmount;
// Prompt user to enter years
cout <<" Enter number of Years : " << endl;
cin >> numberOfYears ;
// Calculate payment
int i;
for( i = numberOfYears ; i < monthlyPayment ; i++)
{
double monthlyPayment = (loanAmount * interestRate) / ( 1.0 - 1.0 / pow(1.0 + interestRate , numberOfYears * 12.0));
monthlyPayment = static_cast<int>(monthlyPayment * 100) / 100.0;
cout << setw(3) << monthlyPayment << i;
cout <<" \n ";
}
int j;
for (j= numberOfYears; j < totalPayment ; j++;)
{
double totalPayment = monthlyPayment * numberOfYears * 12.0;
totalPayment = static_cast<int>(totalPayment * 100) / 100.0;
cout << setw(3) << j;
cout << " \n ";
}
return 0;
}