-3

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);

}
Jite
  • 61
  • 1
  • 1
  • 8
  • 4
    `//call pow function` that is actually not how you call a function. Best to go back to your study book, as it is a pretty basic failure. – Jongware Nov 05 '15 at 22:15
  • `double pow(double x, double n); //call pow function` look up declarations vs definitions vs function calls. – tangrs Nov 05 '15 at 22:16
  • it's unfinished though but why does it skip waiting to let me put in the mortage term? It waits for my input on the 2 previous. – Jite Nov 05 '15 at 22:20
  • Possible duplicate of [Scanf is being ignored](http://stackoverflow.com/questions/32938679/scanf-is-being-ignored) – Jongware Nov 05 '15 at 22:23
  • Calling `pow` from within `pow` will just result in infinite recursion. – interjay Nov 05 '15 at 22:31

1 Answers1

1

You did not call the pow function correctly.

Change the pow function call to:

y = pow(x, n); //call pow function
B-K
  • 56
  • 1
  • 4
  • thanks I discovered that after I posted the question (I forgot to delete that declaration of pow and replace it with the pow; ) but I didn't think that would cause it to skip the last scanf lol thanks everyone – Jite Nov 05 '15 at 22:27