title: Summing up the values of a variable after a loop has ended
body: <p>Hello this is the purpose of my program:</p>
  
  <ol start="23">
  <li>Savings Account Balance</li>
  </ol>
  
  <p>Write a program that calculates the balance of a savings account at the end of a three month period. It should ask the user for the starting balance and the annual interest rate. A loop should then iterate once for every month int he period, performing the following steps:</p>
  
  <p>A) Ask the user for the total amount deposited into the account during that month and add it to the 
       balance. Do not accept negative numbers.</p>
  
  <p>B) Ask the user for the total amount withdrawn from the account during that month and subtract it 
       from the balance. Do not accept the negative numbers or numbers greater than the balance after
       the deposits for the month have been added in.</p>
  
  <p>C) Calculate the interest for that month. The monthly interest rate is the annual interest rate 
       divided by 12. Multiply the monthly interest rate by the average of that month's starting
       and ending balance to get the interest amount for the month. This amount should be added
       to the balance.</p>
  
  <p>After the last iteration, the program should display a report that includes the following 
    information:</p>
  
  <ul>
  <li>Starting balance at the beginning of the three-month period</li>
  <li>total deposits made during the three months</li>
  <li>total withdrawals made during the three months</li>
  <li>total interest posted to the account during the three months</li>
  <li>final balance</li>
  </ul>
  
  <hr>
  
  <p>The problem I am having is that at the end when I display the table my total deposits, withdrawals as well as interest amount are only displaying the last instances at the end of the loop and not the total sum over the three months. Here is my code, sorry if its needlessly complex or messy.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;iomanip&gt;
  using namespace std;
  
  int main()
  {
  //variables
  double depositAmount;
  double withdrawAmount;
  int monthPeriod = 3;
  double startBalance;
  double finalBalance;
  double totalBalance;
  double annInterestRate;
  double monthInterestRate;
  double monthInterestAmount;
  double monthAverageBalance;
  double monthAverageAmount;
  int count;
  
  cout &lt;&lt; "What is your starting balance?   ";
  cin &gt;&gt; totalBalance;
  cout &lt;&lt; "What is your annual rate?  "; 
  cin &gt;&gt; annInterestRate;
  
  for (count = 1; count &lt;= monthPeriod; count++)
  {
      cout &lt;&lt; "Enter total amount deposited for the month  ";
      cin &gt;&gt; depositAmount;
      while (depositAmount &lt; 0)
      {
          cout &lt;&lt; "Error, no negative amounts, please try again." &lt;&lt; endl;
          cin &gt;&gt; depositAmount;
      }
      cout &lt;&lt; "Enter total amount withdrawn for the month  ";
      cin &gt;&gt; withdrawAmount;
      while (withdrawAmount &lt; 0 || withdrawAmount &gt; totalBalance)
      {
          cout &lt;&lt; "Error, no negative amounts or withdrawals greater than your balance. Please try    again" &lt;&lt; endl;
          cin &gt;&gt; withdrawAmount;
      }
      startBalance = totalBalance + depositAmount;
      finalBalance = totalBalance - withdrawAmount;
      totalBalance = startBalance - finalBalance;
      monthInterestRate = annInterestRate * 12;
      monthAverageBalance = (startBalance + finalBalance) / 2;
      monthInterestAmount = monthAverageBalance * monthInterestRate;
      totalBalance = monthInterestAmount + totalBalance;
  }
  cout &lt;&lt; "Your starting balance at the beginning of three months " &lt;&lt; startBalance &lt;&lt; endl;
  cout &lt;&lt; "Total deposits over three months  " &lt;&lt; depositAmount &lt;&lt; endl;
  cout &lt;&lt; "Total withdrawals over three months  " &lt;&lt; withdrawAmount &lt;&lt; endl;
  cout &lt;&lt; "Total interest posted to account over three months " &lt;&lt; monthInterestAmount &lt;&lt; endl;
  cout &lt;&lt; "Final Balance: " &lt;&lt; totalBalance &lt;&lt; endl;
  cout &lt;&lt; "Thank you for using the program!" &lt;&lt; endl;
  return 0;
  }
  </code></pre>