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;