Guess the Number Reverse

I have the codes for guess the number game. Instead of the user, it will be the computer’s turn to guess my random number. I need help on what to change in the codes. Thank you.

I'm Thinking of a Number

Guess the Number I'm Thinking of

<?php global $randnumber, $guess, $counter; $guess=filter_input(INPUT_POST, "guess"); $counter=filter_input(INPUT_POST, "counter"); $randnumber=filter_input(INPUT_POST, "randnumber"); if(!filter_has_var(INPUT_POST,"randnumber")) { print "

Let's play I'm Thinking of a Number (1 - 100)!

\n"; $randnumber=rand(1,100); $counter=0; } else { if($randnumber==$guess) { $counter++; print "Congratulations! You guessed $randnumber in $counter steps. \n
"; } if($guess<$randnumber) { $counter++; print "The number $guess is too low. Guess a higher number \n
"; } if($guess>$randnumber) { $counter++; print "The number $guess is too high. Guess a lower number \n
"; } } if ($guess != $randnumber) { guessForm(); } else { print <<<HERE Press Here to Restart Game HERE; } function guessForm() { global $randnumber, $guess, $counter; print <<<HERE

HERE; } ?>

Here’s my codes. I need help in setting the conditions if the guess is high or low. Thank you.

I'm Thinking of a Number

Guess the Number

<?php global $randnumber, $compGuess, $counter; $compGuess=filter_input(INPUT_POST, "compGuess"); $counter=filter_input(INPUT_POST, "counter"); $randnumber=filter_input(INPUT_POST, "randnumber"); if(!filter_has_var(INPUT_POST,"randnumber")) { $randnumber=rand(1,100); $counter=0; if(!filter_has_var(INPUT_POST, "compGuess")) { print "Let's play I will guess your number"; } } else { $compGuess = rand(1,100); if($compGuess == $randnumber) { $counter++; print "Congratulations! You guessed $randnumber in $counter steps. \n
"; } if($compGuess<$randnumber) { $counter++; print "The number $compGuess is too low. Guess a higher number \n
"; print "my random number $randnumber
"; } if($compGuess>$randnumber) { $counter++; print "The number $compGuess is too high. Guess a lower number \n
"; } } if ($compGuess != $randnumber) { guessForm(); } else { print <<<HERE Press Here to Restart HERE; } function guessForm() { global $randnumber, $compGuess, $counter; print <<<HERE

HERE; } ?>
Sponsor our Newsletter | Privacy Policy | Terms of Service