title: (PHP) Adding a 'guess counter' to a random number game
body: <p>I need to modify a block of code and add a counter regarding how many times it took the user to guess the right number.</p>
  
  <p>I was wondering how it would be properly implemented into my code.</p>
  
  <p>This is what I have so far.</p>
  
  <pre><code>&lt;?php
  
  if (!isset($_POST["guess"])) {
       $message = "Welcome to the guessing machine!";
       $count++; //Declare the variable $count to increment by 1.
       $_POST["numtobeguessed"] = rand(0,1000);
  } else if ($_POST["guess"] &gt; $_POST["numtobeguessed"]) { //greater than
      $message = $_POST["guess"]." is too big! Try a smaller number.";
  
  } else if ($_POST["guess"] &lt; $_POST["numtobeguessed"]) { //less than
      $message = $_POST["guess"]." is too small! Try a larger number.";
  
  } else { // must be equivalent
      $message = "Well done! You guessed the right number in ".$count." attempt(s)!"; 
          //Include the $count variable to the $message to show the user how many tries to took him.
  }
  ?&gt;
  &lt;html&gt;
      &lt;head&gt;
          &lt;title&gt;A PHP number guessing script&lt;/title&gt;
      &lt;/head&gt;
      &lt;body&gt;
      &lt;h1&gt;&lt;?php echo $message; ?&gt;&lt;/h1&gt;
          &lt;form action="" method="POST"&gt;
          &lt;p&gt;&lt;strong&gt;Type your guess here:&lt;/strong&gt;
              &lt;input type="text" name="guess"&gt;&lt;/p&gt;
              &lt;input type="hidden" name="numtobeguessed" 
                     value="&lt;?php echo $_POST["numtobeguessed"]; ?&gt;" &gt;&lt;/p&gt;
      &lt;p&gt;&lt;input type="submit" value="Submit your guess"/&gt;&lt;/p&gt;
          &lt;/form&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>