title: Incrementing variable in a if statement
body: <p>Here is a snippet of code (an <code>else</code> clause):</p>
  
  <pre><code>else { // for operators
              int count = 1;
              if (sub.compareTo("+") == 0){ //if + operator
                  double d1=stack.pop();
                  double d2=stack.pop();
                  answer=d1+d2;
                 //first two items on stack added
                  stack.put(answer); // put ans on stack
                 System.out.println(count+ ") "+d1+ " + " +d2 + " = " +answer); // display ans
                 count++;
              }
              if (sub.compareTo("-") == 0){ //if - operator
                  double d1=stack.pop(); //pop first two items on stack
                  double d2=stack.pop();
                  answer =d2-d1; //subtract the items
                  stack.put(answer);//put ans on stack
                  System.out.println(count+ ") "+d2+ " - " +d1 + " = " +answer);///display answer
                  count++;
              }
  }
  </code></pre>
  
  <p>This code tries to evaluate basic mathematical operations using a <code>stack</code>. Examples are:</p>
  
  <ol>
  <li>2 + 2 = 4</li>
  <li>4 + 4  = 8</li>
  </ol>
  
  <p>I want to use the <code>count</code> variable to display the number but it stays at 1. Do you know why?</p>