-
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
-
There is a difference between interest/(12*100) and interest/12*100.
-
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.
-
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
-
hey nonoob,
The numbers doesn't make sense for me, a house for 46 thousand and 2316 monthly!!!
-
I need the 100 to be divided as the user will enter it in percentage.
-
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.
-
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?!
-
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?
-
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.
-
-
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
-
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.
-
Right Tabstop, I'll have to edit the whole program as I'm working in months, do you think the equations are right
-
All the formulas are in months. But they appear to be right.