Help with mortgage calculator

This is a discussion on Help with mortgage calculator within the C++ Programming forums, part of the General Programming Boards category; I have to make a program that calculates how long it will take to pay off a 350,000 mortgage, and ...

  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    7

    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;

  2. #2
    Banned nickname_changed's Avatar
    Join Date
    Feb 2003
    Location
    Australia
    Posts
    986
    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

  3. #3
    RoD
    RoD is offline
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    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;
    }

  4. #4
    Banned nickname_changed's Avatar
    Join Date
    Feb 2003
    Location
    Australia
    Posts
    986
    Or if you want to give them their $566 back, take the last number and multiply by -1.

  5. #5
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398
    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
    Last edited by DougDbug; 03-28-2003 at 07:36 PM.

  6. #6
    Registered User
    Join Date
    Mar 2003
    Posts
    7
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. GUI Calculator - Critique
    By The Brain in forum Windows Programming
    Replies: 1
    Last Post: 02-25-2006, 04:39 AM
  2. Calculator + LinkedList
    By maro009 in forum C++ Programming
    Replies: 20
    Last Post: 05-17-2005, 01:56 PM
  3. Need help with calculator program
    By Kate in forum C# Programming
    Replies: 1
    Last Post: 01-16-2004, 10:48 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21