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