title: how to add a counter
body: <p>I am confused on how to add a counter to my code - I'm writing a 2 player number guessing game and I want to add the number of guesses it took to satisfy the program. </p>
  
  <p>This is what I've got so far:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;cstdlib&gt;
  #include &lt;ctime&gt;
  
  int main()
  {
  
      int x;
      int  guess;
  
      std::cout &lt;&lt; "Enter the number for the player to guess.";
      std::cin &gt;&gt; x;
  
      do
      {
          std::cout &lt;&lt; "Enter your guess.";
          std::cin &gt;&gt; guess;
          if (guess &gt; x)
              std::cout &lt;&lt; "lower\nEnter your guess.\n";
          else if (guess &lt; x)
              std::cout &lt;&lt; "higher\nEnter your guess.\n";
          else
              std::cout &lt;&lt; "You guessed it!\n";
      } while (guess != x);
  
      return 0;
  }
  </code></pre>