In my mortage program function (I'm writing it in it's own C file then putting it in a larger program) it displays the monthly payment as $0 because when I ask for the term of the mortage it skips asking me for the input and just goes straight to the answer. Also, unrelated but is there a way to say like "I have this question too" on someone else's because there are a lot of similar programs out there (mortage has a lot of questions) or is this the best way? I don't want to clutter up the site.
Edit: now it's saying "Segementation fault" after I put 24 in for the mortage terms(24 months)
Edit: now it's saying -0.0000 for the payment
int main()
{
double x, m, n, r, p, y =0; //m is monthly payment, x is pow
printf("Enter principal amount now: ");
scanf("%d", &p);
printf("Enter interest rate (0.01 = 1%) now: ");
scanf("%lf", &r);
printf("Enter payment period in months now: ");
scanf("%lf",&n);
printf("Calculating... ");
//m = p [ r(1 + r)^n ] / [ (1 + r)^n - 1]; // mortage formula
x= 1+r;
y = pow(x, n);//call pow function
m= (p*(r*y))/(y-1);
printf("The monthly payment for your mortage is: %lf \n",m); //display mortage monthly payment
}
double pow(double x, double n)
{
//double y =0;
//base=x;
//exp=n;
return(0);
}