


Thread Tools  Display Modes 
Mar 26th, 2005, 2:50 PM  #1 
Newbie
Join Date: Mar 2005
Posts: 1
Rep Power: 0

Mortgage Calculator
I have been working for hours trying to get my mortgage calculator program to work. The purpose of the program is to allow user input of the loan amount, interest rate, and term in years, and then display the mortgage payment amount. I also have to list the loan balance and interest paid over the term of the loan. I am fine with the calculation of the mortgage payment amount. The problem is that I am unable to get the loan balance for each payment and the interest paid for each payment to calculate correctly. Any assistance with what I am doing wrong in my calculations would be greatly appreciated!
#include <iostream> #include <cmath> #include <iomanip> using namespace std; int main() { //local variables 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; //Variable declarations float RATE=INT_RATE/100; //converts interest rate into decimal format float monthlyInterestRate; //monthly interest rate int numberOfPayments; //total number of payments float monthlyPaymentAmt; //monthly payment amount int monthly_payments_counter;//counter that keeps track of the payment number float loanBalance=LOAN_AMOUNT; //loan balance float monthlyIntPymt; //monthly interest payment int divide_list = 0; //displays a partial list for the user char list_more; //enables the user to continue viewing a partial list float monthlyPrincipalPymt; //monthly principal payment //CALCULATIONS //monthly interest rate monthlyInterestRate = RATE / 12; //number of payments numberOfPayments = TERM_YEARS * 12; //monthly payments monthlyPaymentAmt = (LOAN_AMOUNT* pow(monthlyInterestRate + 1, numberOfPayments) * monthlyInterestRate)/(pow(monthlyInterestRate + 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 <<" is $"<<monthlyPaymentAmt<<" a month\n"; cout<<"\n"; cout<<"Payment Number\tLoan Balance\tInterest Paid\n"; cout<<"\t\t\n"; //List the payment number, loan balance, and interest paid //for each period for (monthly_payments_counter=1; monthly_payments_counter<=(TERM_YEARS * 12); ++monthly_payments_counter) { loanBalance = ((LOAN_AMOUNT * (1+monthlyInterestRate))  (monthly_payments_counter * monthlyPaymentAmt)); monthlyInterestRate = INT_RATE / 12; monthlyIntPymt = loanBalance * monthlyInterestRate; monthlyPrincipalPymt = monthlyPaymentAmt  (loanBalance * INT_RATE); loanBalance = loanBalance  monthlyPrincipalPymt; //displays a partial list and allows the user either continue viewing //the list, enter a new loan, or exit the program if (divide_list == 12) { cout <<"Type 'c' to continue viewing the list, " <<"'n' to enter a new loan, or 'e' to exit: "; cin >> list_more; if ((list_more == 'c')  (list_more == 'C')) divide_list = 0; else if ((list_more == 'n')  (list_more == 'N')) break; else if ((list_more == 'e')  (list_more == 'E')) return 0; } //displays the results on the screen for each payment number cout<<monthly_payments_counter<<"\t\t" <<loanBalance<<"\t" <<monthlyIntPymt<<"\t\t\n"; ++divide_list; if(loanBalance<=0) break; } //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'))); cout<<"Thanks for using the calculator!\n"; return 0; } 
Mar 26th, 2005, 3:07 PM  #2 
Security Specialist
Join Date: Sep 2004
Posts: 1,053
Rep Power: 14

I should beable to do this we just finished stuff like this in my personal finance class :p

Jan 4th, 2008, 5:54 AM  #3 
Newbie
Join Date: Jan 2008
Posts: 1
Rep Power: 0

Re: Mortgage Calculator
monthly interest rate is calculated wrongly i guess .....
annual interest rate /12 can cannot b used in this formula ...... APR/12 i.e. Annual Percentage Rate / 12 should be used ..... APR calculation is however a tough job ..... As this topic is posted long back nd im also working on the same problem if u hav the solution please give the calculations part fo the rectified ..... 
Jan 4th, 2008, 8:47 AM  #4 
Programming Guru

Re: Mortgage Calculator
invicta, there was no reason to bump a thread that's almost three years old. Especially since sasha81 is long gone and won't be able to provide the completed problem for you. If you have your own questions about this assignment, I'd recommend you open up another thread for help, rather than confuse people by resurrecting this one.
Last edited by Sane; Jan 4th, 2008 at 8:58 AM. 
Apr 1st, 2009, 7:38 AM  #5 
Banned

1MortgageCalculator.info : 21 Advanced Mortgage Calculators
Hello,
The forum is very informative. Feel great to be a part of the this website. Wanted to share a website which might be very use full for some of the people here. I was doing some research on my mortgage refinance issue when I came across this website. It lists some 21 mortgage calculators that I did not see anywhere on the internet so I was compelled to share it. The coolest thing was that it also gives you the findings in plain English as well so you can understand the results of your findings easily. The website can be accessed here. Mortgage Calculator Thanks 
Bookmarks 
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)  
Thread Tools  
Display Modes  

