Hi,
I need to create a mortgage calculator program that asks the user to input the loan amount, mortgage term, & interest rate. I am to display the mtge payment amount. I am fine with all of this.
I am then to list the loan balance and interest paid for each pymt over the term of the loan. On longer-term loans, I am not to allow the list to scroll off the screen. I need to display a partial list and then allow the user to continue the list. This is where I am unsure of where to start. I began a for loop, but I don't know if this is in the right direction. I also can't find the formula for calculating the balance. Can anyone point me in the right direction to get started?
Code:
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
int main()
{
float LOAN_AMOUNT=0; //loan amt
float INT_RATE=0; //interest rate
int TERM_YEARS=0; //loan term in years
char quit; //determines if user wants to quit
do
{
//output message asking for loan amt
cout<<"Input the total loan amount:\n";
//input data
cin>>LOAN_AMOUNT;
//output message asking for interest rate
cout<<"Input the annual interest rate:\n";
//input data
cin>>INT_RATE;
//output message asking for term in years of loan
cout<<"Input the length of the loan in years:\n";
//input data
cin>>TERM_YEARS;
//local variables
float RATE=INT_RATE/100; //rate in decimal format
float monthlyInterest; //monthly interest rate
int numberOfPayments; //total number of payments
float payment; //monthly payment
float balance; // loan balance
//calculate values
monthlyInterest=RATE/12; //monthly interest is rate/12
numberOfPayments=TERM_YEARS*12; //# of pymts is length of loan*12
payment=(LOAN_AMOUNT*
pow(monthlyInterest + 1, numberOfPayments)
* monthlyInterest)/(pow(monthlyInterest + 1,
numberOfPayments) - 1); //pow returns x raised to the power of y
//output results
cout<<fixed<<setprecision(2)//cout writes text to the screen
<<"\n";
cout<<"Your monthly payment for "
<<TERM_YEARS <<" years\n";
cout<<"for an Interest Rate of "
<<INT_RATE <<"%\n";
cout<<"on a Loan Amount of $"
<<LOAN_AMOUNT <<":\n";
cout<<"\n";
cout<<"$"
<<payment
<<" a month\n";
cout<<"\n";
cout<<"Payment Number\tLoan Balance\tInterest Paid\n";
cout<<"--------------\t------------\t-------------\n";
for (int paymentNumber=1; paymentNumber< ? ; ++paymentNumber)
{
cout<<paymentNumber<<'\n';
}
//user can continue in a loop or quit
//output
cout<<"\n";
cout<<"Enter C to continue, Q to quit >";
//user input
cin>>quit;
cout<<"\n";
while((quit!='q') && (quit!='Q') &&
(quit !='c') && (quit !='C'));
}
while((quit!='q') && (quit!='Q'));
cout<<"Thanks for visiting\n";
}