title: Monthly payments C program
body: <p>Need some help with calculating  the fixed monthly payment (P) required to fully amortize a loan of L dollars over a term of n months at a monthly interest rate of i. The given formula is: P = L[i(1 + i)n]/[(1 + i)n - 1]. I wrote a code but it didn't calculate Payment. I'm wondering if it is because I use double type together with int (for number of months) or the problem with formula?! Please help.</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  #include &lt;math.h&gt;
  
  
  double calculatePayments(double rate, double loan, int payments);
  
  
  int main() {
  
      double principal, i, monthlyP;
      int month;
  
  
          printf ("Enter the principal amount: ");
          scanf ("%f", &amp;principal);
  
          printf ("Enter the interest amount: ");
          scanf ("%f", &amp;i);
  
          printf ("Enter the term in months: ");
          scanf ("%d", &amp;month);
  
          monthlyP = calculatePayments (i, principal, month);
  
          printf ("The monthly payment amount is %.2f: ", monthlyP);
          return 0;
      }
  
  
  double calculatePayments(double rate, double loan, int payments) {
  
      double mPayments;
      mPayments = loan*(rate*(1 + rate)*payments)/((1 + rate)*payments - 1);
  
      return mPayments;
  }
  </code></pre>