title: For while loop C++ basic interest calculator
body: <p>For your 21st birthday, your grandmother opens a savings account for you and deposits $1000 into the account.  The savings account pays a 3% interest on the account balance.  If you don't deposit any more money into the account, and you don't withdraw any money from the account, how much will your savings account be worth at the end of 1 through 5 years?</p>
  
  <p>Create a program that gives you the answers.  You can calculate the answers using the following formula: b = p * (1 + r)n .  In the formula, p is the principal (the amount of the deposit), r is the annual interest rate (3%), n is the number of years (1 through 5), and b is the balance in the savings account at the end of the nth year.
  Use a for loop.</p>
  
  <p>Any help will be greatly appreciated</p>
  
  <p>This is what I have so far and all I get is an infinite loop</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;cmath&gt;
  #include &lt;iomanip&gt;
  using namespace std;
  
  void main()
  {
  // Inputs //
  
  double princ = 0.0;
  double rate = 0.0;
  int years = 0;
  int year = 1;
  double total = 0.0;
  
  // Ask User For INFO //
  
  cout &lt;&lt; "What is the principle? ";
  cin &gt;&gt; princ;
  cout &lt;&lt; "What is the rate in decimal? ";
  cin &gt;&gt; rate;
  cout &lt;&lt; "how many years? ";
  cin &gt;&gt; years;
  
  
  
  for (double total; total = princ*(1+rate)*year;)
  {
  cout &lt;&lt; "The balance after year " &lt;&lt; year &lt;&lt; " is "&lt;&lt; total &lt;&lt; endl &lt;&lt; endl;
  year += 1;
  }
  
  while((years + 1)!= year);
  
  system("pause");
  }
  </code></pre>