Hello,

I have to program a mortgage calculator based on the equal monthly payments formula. I have everything set except i keep getting 1.#INF as my value. I know this means infinity but can anyone tell me why?

thanks!

here is the code:

#include<stdio.h>

#include<conio.h>

#include<math.h>

main ()

{

double price_of_the_house, amount_financed, annual_rate, monthly_pay, total_pay, r;

int n;

printf("Enter the price of the house (in $): ");

scanf("%lf", &price_of_the_house);

printf("Enter the amount to be financed (in $): ");

scanf("%lf", &amount_financed);

printf("Enter the annual percentage rate (in %%): ");

scanf("%lf", &annual_rate);

printf("Enter the term in number of months: ");

scanf("%lf", &n);

r = annual_rate/12;

monthly_pay = amount_financed * r * pow(1+r,n)/(pow(1+r,n) - 1);

total_pay = monthly_pay * 12;

if ( price_of_the_house < 0 || amount_financed < 0 || annual_rate <= 0 || n < 0

|| amount_financed > 0.8 * price_of_the_house || n % 12 != 0 || n > 480 )

{

printf("One of the following errors have occurred:\n");

printf("1) Price of house, amount financed, annual rate or number of months is/are negative.\n");

printf("2) Annual rate or number of months is/are zero.\n");

printf("3) Amount financed is larger than 80%% of the price of the house.\n");

printf("4) The number of months is not a multiple of 12.\n");

printf("5) The number of months is greater than 480.\n");

}

else

{

printf("The price of the house is: %.2f $\n", price_of_the_house);

printf("The amount to the financed is: %.2f $\n", amount_financed);

printf("The annual percentage rate is: %.2f %%\n", annual_rate);

printf("Your monthly payment is: %f $\n", monthly_pay);

printf("Your total payment will be: %f $\n", total_pay);

}

getch(); return 0;

}