title: Problems with calculating total interest in a loan calculator program (C++)
body: <p>I've been developing a simple loan calculator program for my c++ class, and I cannot for the life of me figure out where i'm going wrong. The whole program works as intended except for how the total interest for the loan is calculated. I feel like the answer here is simple, but I cannot see it.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;iomanip&gt;
  #include &lt;cmath&gt;
  using namespace std;
  
  int main()
  {
      int numberOfPayments;
          double monthlyInterestRate;
          double Loan;
          double monthlyPayment;
          double annualInterestRate;
          double interestTotal;
          double loanTotal;
  
  
      cout &lt;&lt; "Enter the loan amount (principal) --&gt;  ";
      cin &gt;&gt; Loan;
      cout &lt;&lt; "Enter the YEARLY interest rate as a percentage --&gt;  ";
      cin  &gt;&gt; annualInterestRate;
      cout &lt;&lt; "Enter the number of payments --&gt;  ";
      cin &gt;&gt; numberOfPayments;
  
      monthlyInterestRate = annualInterestRate / 12;
      monthlyInterestRate = monthlyInterestRate / 100;
      monthlyPayment = (monthlyInterestRate)  *   pow((1 + monthlyInterestRate), numberOfPayments) /  (pow((1 + monthlyInterestRate), numberOfPayments) - 1) * Loan; // Amount of monthly payments
      loanTotal = (monthlyPayment * numberOfPayments); // Total amount due for loan
      interestTotal = monthlyInterestRate * numberOfPayments  * monthlyPayment; 
  
  
      cout &lt;&lt; monthlyInterestRate &lt;&lt; endl;
      cout &lt;&lt; "Loan Amount:                                    $" &lt;&lt; setw(8) &lt;&lt; Loan &lt;&lt; endl;
      cout &lt;&lt; "Yearly Interest Rate:                            " &lt;&lt; setw(8) &lt;&lt; annualInterestRate &lt;&lt; "%" &lt;&lt; endl;           
      cout &lt;&lt; "Number of Payments:                              " &lt;&lt; setw(8) &lt;&lt; numberOfPayments &lt;&lt; endl;
      cout &lt;&lt; "Monthly Payment:                                $" &lt;&lt; setw(8) &lt;&lt; setprecision(5) &lt;&lt; monthlyPayment &lt;&lt; endl;
      cout &lt;&lt; "Amount Paid Back:                               $" &lt;&lt; setw(8) &lt;&lt; setprecision(7) &lt;&lt; loanTotal &lt;&lt; endl;
      cout &lt;&lt; "Interest Paid:                                  $" &lt;&lt; setw(8) &lt;&lt; setprecision(5) &lt;&lt; interestTotal  &lt;&lt; endl;
      cout &lt;&lt; "\n\nProgram Over";
      cout &lt;&lt; "\n\n\nPress Enter to end --&gt;";
      cin.ignore();
      cin.get();  
      return 0;
  }
  </code></pre>