Programming Forums
User Name Password Register

RSS Feed

Thread Tools Display Modes
Old Mar 26th, 2005, 2:50 PM   #1
Join Date: Mar 2005
Posts: 1
Rep Power: 0 sasha81 is on a distinguished road
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
        //output message asking for loan amt
		cout<<"Input the total loan amount:\n";

		//input data

		//output message asking for interest rate
		cout<<"Input the annual interest rate:\n";

		//input data
		//output message asking for term in years of loan
		cout<<"Input the length of the loan in years:\n";

		//input data

		//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

		//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
		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<<"Payment Number\tLoan Balance\tInterest Paid\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'))
				else if ((list_more == 'e') || (list_more == 'E'))
					return 0;
			//displays the results on the screen for each payment number

		//user can continue in a loop or quit
		cout<<"Enter C to continue, Q to quit >";

		//user input

	while (((quit!= 'q') && (quit!= 'Q')) || ((quit == 'c') && (quit == 'C')));

	cout<<"Thanks for using the calculator!\n";

	return 0;
sasha81 is offline   Reply With Quote
Old Mar 26th, 2005, 3:07 PM   #2
Security Specialist
Benoit's Avatar
Join Date: Sep 2004
Posts: 1,053
Rep Power: 15 Benoit will become famous soon enough
I should beable to do this we just finished stuff like this in my personal finance class :p
Benoit is offline   Reply With Quote
Old Jan 4th, 2008, 5:54 AM   #3
Join Date: Jan 2008
Posts: 1
Rep Power: 0 invicta is on a distinguished road
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 .....
invicta is offline   Reply With Quote
Old Jan 4th, 2008, 8:47 AM   #4
Programming Guru
Sane's Avatar
Join Date: Apr 2005
Location: Google / Kitchener
Posts: 4,154
Rep Power: 18 Sane has a spectacular aura aboutSane has a spectacular aura about
Send a message via MSN to Sane
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.
Sane is offline   Reply With Quote
Old Apr 1st, 2009, 7:38 AM   #5
Join Date: Feb 2009
Location: Hungary
Posts: 1
Rep Power: 0 wampipsTips is on a distinguished road
Send a message via ICQ to wampipsTips : 21 Advanced Mortgage Calculators

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

wampipsTips is offline   Reply With Quote


« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

DaniWeb IT Discussion Community
All times are GMT -5. The time now is 3:27 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC