title: While loop calculation issue
body: <p>I'm currently working on a Java program (for school) that prints two statements when a user enters a starting balance for their account.</p>
  <p>So for example, if the user inputs $10,000, there will be two statements that print at the same time. One tells them how long it will take for their account to reach $100,000, and the other when it reaches $1,000,000.</p>
  <p>Now I have the code, which I'll post below, and it works (it gets me a result that's close to what is required), however, the issue I'm having is with the math itself. I'll post the code and explain:</p>
  <pre><code>public static void main(String[] args) {
      int startBalance = 0;
      int storedBalance = 0;
      int years = 0;
      try (Scanner stdln = new Scanner(System.in)) {
          System.out.println(&quot;Please enter your starting balance: &quot;);
          startBalance = stdln.nextInt();
      }
      
      while (storedBalance &lt; 100000)
      {   
          storedBalance = startBalance + (storedBalance * 2) ;
          ++years;
      } 
      System.out.println(&quot;It will take &quot; + years + &quot; year(s) for your bank balance to reach &quot; + storedBalance + &quot;.&quot;);
      
      while (storedBalance &lt; 1000000)
      {   
          storedBalance = startBalance + (storedBalance * 2);
          ++years;
      } 
      System.out.println(&quot;It will take &quot; + years + &quot; year(s) for your bank balance to reach &quot; + storedBalance + &quot;.&quot;);
  }
  </code></pre>
  <p>}</p>
  <p>So in theory, the startBalance is supposed to double until it reaches $100,000 or more, in which case the years it takes to reach over $100,000 is calculated and the statement gets printed (same with the second While loop but with $1,000,000). So if the user entered $10,000, the storedBalance variable for the first While loop should go $20k, $40k, $80k, $160k, but with the math I currently have it goes $10k, $30k, $70k, $150k.</p>
  <p>I've also tried:</p>
  <p>storedBalance = (startBalance * 2) + storedBalance;</p>
  <p>and it works, but the issue is that instead of doubling the amount (10k to 20k, 20k to 40k, 40k to 80k, etc.) it just adds 20k to the previous number, which makes sense since the logic in that statement if the startBalance is 10k is: (10,000 * 2) + storedBalance, so the logic within the brackets remains constant and doesn't adjust as the number changes but the stored balance increases with every loop.</p>
  <p>So I know that something is missing because year 1 = $10k when it should be $20k but the years it takes to get there are correct. I have a feeling my math is incorrect as I'm not doubling the initial value and I'm just adding the storedBalance to it.</p>
  <p>Any and all responses are greatly appreciated. Thank you in advance.</p>