Thread: calculating mortgage!!!

  1. #1
    Registered User
    Join Date
    Oct 2008
    Posts
    9

    calculating mortgage!!!

    I am having troubles in my program for the mortgage calculations. the program works fine, but I keep in getting weird numbers:
    Here is my program, if you have enough time, can you check for me, and provide me with some feedback, Thanks
    --------------------------------------------------------------------------
    insert
    Code:
    #include <stdio.h>
    #include <math.h>
    double price(double sf,double down)
    {
            double cost;
            cost=sf*18-(down/sf);
            return(cost);
    }
    double annual_fuel(double sf)
    {
            double fuel_cost;
            fuel_cost=sf*0.85/12;
            return(fuel_cost);
    }
    double mortgage(double i,double p,double n)
    {
            return(i*p/(1-pow((1+i),-1*n)));
    }
    int main(){
    double down_pay,sq_foot,mon_interest_rate,num_pay,principle;
    printf("\nPlease, Enter the sq. Footage:  ");
    scanf("%lf",&sq_foot);
    printf("\nNow, Enter the Down Payment: ");
    scanf("%lf",&down_pay);
    printf("\nPlease, Enter the monthly interest rate in percentage: ");
    scanf("%lf",&mon_interest_rate);
    mon_interest_rate=mon_interest_rate/(12*100); // convert from annual to
    monthly rate
    printf("\nplease, Enter the annual number of payments:  ");
    scanf("%lf",&num_pay);
    principle=price(sq_foot,down_pay)-down_pay+annual_fuel(sq_foot);
    printf("\n      Your house cost is $%0.2lf",price(sq_foot,down_pay));
    printf("\n      Your cost after fuel cost is
    $%0.2lf",annual_fuel(sq_foot)+price(sq_foot,down_pay));
    printf("\n      Your monthly payment is $%0.2lf\n
    ",mortgage(mon_interest_rate,principle,num_pay));
    return 0;
    }
    -----------------------------------------------------------------------
    -bash-3.2$ gcc -o output monthly_cost.c -lm
    -bash-3.2$ ./output

    Please, Enter the sq. Footage: 2600

    Now, Enter the Down Payment: 20000

    Please, Enter the monthly interest rate in percentage: 5.6

    please, Enter the annual number of payments: 12

    Your house cost is $46792.31
    Your cost after fuel cost is $46976.47
    Your monthly payment is $2316.81

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    There is a difference between interest/(12*100) and interest/12*100.

  3. #3
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,834
    Good eye! The program looked alright to me.
    This might be questionable:
    Code:
    cost=sf*18-(down/sf)
    because sf can be factored out a bit. Just a thought. Could be ok. I just don't know what it was meant to do... or in general, where the program's output isn't what was expected.

  4. #4
    Registered User
    Join Date
    Oct 2008
    Posts
    9
    Please, Enter the sq. Footage: 2600

    Now, Enter the Down Payment: 20000

    Please, Enter the monthly interest rate in percentage: 5.6
    that's if I change it to 12*100 still too low

    please, Enter the annual number of payments: 12

    Your house cost is $46792.31
    Your cost after fuel cost is $46976.47
    Your monthly payment is $1258902.14
    Last edited by beho86; 10-22-2008 at 06:44 PM.

  5. #5
    Registered User
    Join Date
    Oct 2008
    Posts
    9
    hey nonoob,
    The numbers doesn't make sense for me, a house for 46 thousand and 2316 monthly!!!

  6. #6
    Registered User
    Join Date
    Oct 2008
    Posts
    9
    I need the 100 to be divided as the user will enter it in percentage.

  7. #7
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,834
    Ok, I don't have a good feel for what numbers sound good. You're using a lot of magic numbers like 18 and 0.85 so I couldn't begin to second-guess.

    For one thing you've asked for monthly interest, yet your program converts from yearly to monthly... so I wasn't sure which way it's expecting it.

  8. #8
    Registered User
    Join Date
    Oct 2008
    Posts
    9
    You're right, the only thing that I am not sure about, when I add the fuel cost, should I add that to the monthly bill?!

  9. #9
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Since you're doing a one-year mortgage, 2316/month is probably about right. Perhaps you don't intend to do a one-year mortgage?

  10. #10
    Registered User
    Join Date
    Oct 2008
    Posts
    9
    That's right, if I'm asking the user for annual number or payments, can he enter more than 12, or I should make it years. I don't know.

  11. #11
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    It's your program.

  12. #12
    Registered User
    Join Date
    Oct 2008
    Posts
    9
    okay, here's the main question that I was asked to do:
    Create a working program that will prompt the user for the necessary input information and display the monthly housing costs;

    Equations:
    Price = square footage * 18 - (down payment/square footage)

    Mortgage= iP/(1-(1+i)^(-n)
    i= monthly interest rate
    p=principle ( money you borrowed)
    n= number of payments ( 30 yr mortgage=360, 15 yr mortgage=180)

    annual Fuel cost = square footage * 0.85

  13. #13
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Since monthly is assumed in the problem and the formulas, you don't need to ask for that, but you do need to ask for years.

  14. #14
    Registered User
    Join Date
    Oct 2008
    Posts
    9
    Right Tabstop, I'll have to edit the whole program as I'm working in months, do you think the equations are right

  15. #15
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    All the formulas are in months. But they appear to be right.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Recursion
    By Lionmane in forum C Programming
    Replies: 11
    Last Post: 06-04-2005, 12:00 AM
  2. Taking input while calculating
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 07-12-2002, 04:47 PM

Tags for this Thread