title: Calculating the remaining loan balance
body: <p>I am trying to write a program in C to calculate the remaining loan balance after a given number of months, given the balance, monthly payment amount, and interest rate. (Each month, the balance increases by (balance * (interest rate/12)), and decreases by the payment amount.)</p>
  
  <p>My code to calculate the balance for each month is as follows:</p>
  
  <pre><code>for (i = 1; i &lt;= n; i++) {
      loanAmount += (loanAmount * (intRate/12));
      loanAmount -= monthlyPayment;
      printf("The balance after month %d is %.2f\n", i, loanAmount);
  }
  </code></pre>
  
  <p>I put in some values (<code>loanAmount = 1000</code>, <code>intRate = 12</code>, <code>monthlyPayment = 100</code>, <code>n = 3</code>), and I expected the result to be 910.00 after month 1, 819.10 after month 2, and 727.29 after month 3. However, I got these results instead:</p>
  
  <pre><code>Enter the loan amount:
  1000
  Enter the interest rate:
  12
  Enter the monthly payment amount:
  100
  Enter the number of monthly payments:
  3
  The balance after month 1 is 1900.00
  The balance after month 2 is 3700.00
  The balance after month 1 is 7300.00
  </code></pre>
  
  <p>What am I doing wrong in my code? I thought my algorithm was correct.</p>