# Help with mortgage calculator

• 03-28-2003
webvigator2k
Help with mortgage calculator
I have to make a program that calculates how long it will take to pay off a 350,000 mortgage, and how much is paid out each month until the balance is zero. I used a while loop that counts down correctly, until the last payment. The monthly pay rate is 2225, and the last payment is about 1600...so when it does that part, the balance becomes something like -566 (which really means a credit balance). How do I fix this thing from going over so to speak (in other words, how do I get it to deal with the overpayment for the last month?)

Source code (some of these variables I have yet to use, I'm just trying to get this calculation part down):

#include <iostream.h>
#include <iomanip.h>

int main()
{
int balance, months, years, count, pay;
float interest, amt, lastamt, total, mort;

count = 0;
total = 350000;
pay = 2225;
mort = 350000;
interest = .065;

while(mort>0){
mort = mort + (mort * (interest/12)) - pay;
count = count++;

cout << "mortage is: \n" << mort << endl;
}

return 0;
• 03-28-2003
nickname_changed
I don't get it, do you want to give the person \$566 back? Might help more if I understood mortgages more, but I don't get what you're trying to ask.

~ Paul
• 03-28-2003
RoD
dont get it either, but this will stop the negative number...

Code:

```#include <iostream.h> #include <iomanip.h> int main() { int balance, months, years, count, pay; float interest, amt, lastamt, total, mort; count = 0; total = 350000; pay = 2225; mort = 350000; interest = .065; while(mort>0 && pay <= mort){ mort = mort + (mort * (interest/12)) - pay; count = count++; cout << "mortage is: \n" << mort << endl; } return 0; }```
• 03-28-2003
nickname_changed
Or if you want to give them their \$566 back, take the last number and multiply by -1.
• 03-28-2003
DougDbug
You could subtract the overpayment amount from the usual payment and display a message like cout << "Last payment is" << pay-mort ; Where mort is negative at the end.

Also, you said you're supposed to find out how long it takes, so don't forget to display the count (number of months) or months and years.

P.S. There are formulas to calculate this stuff more directly. I don't have my finance books with me, and I don't remember them. But, that wouldn't be any fun... no looping :(
• 03-28-2003
webvigator2k
Here's the assignment in her words (she's a real pain in the ass, and she doesnt teach the material very well...I have half a notebook of notes, she barely lets us touch the computers):

Use a while loop in this program.

Write a program which will determine the number of months and years it
will take to pay off a \$350,000 mortgage at 6.5% per year interest rate if
monthly payments are \$2,225.
Output : the time it takes in months and years to pay off the mortgage
the total interest paid over the time of the loan
the amount of the last payment

Warning. Make sure you update statistics for the last payment.