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 NumberGuess 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;
}
?>
"; } 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; } ?>