I am working on hidden fields and cannot figure this out. I’m doing the “I’m thinking of a number” in reverse so the program has to guess what number the user is thinking of in 7 guesses or less.
Guess a number in reversePick a number between 1 and 100 and I will try a guess it!
[php]<?php
$tooHigh = isset($_POST[‘tooHigh’]) ? $_POST[‘tooHigh’] : 100;
$tooLow = isset($_POST[‘tooLow’]) ? $_POST[‘tooLow’] : 0;
$guess = isset($_POST[‘guess’]) ? $_POST[‘guess’] : 0;
if ($_POST['select']=="correct"){
print "<br>I got it right!<br>"; }
else if ($_POST['select']=="tooHigh"){
$tooHigh = $guess - 1;
$guess = round(tooLow + tooHigh)/2;
}
else if ($_POST['select']=="tooLow"){
$tooLow = $guess + 1;
$guess = round (tooLow + tooHigh)/2;
}
$guess=rand($tooLow, $tooHigh);
print <<<HERE
Correct!
Too High
Too Low
My guess is $guess
HERE;
?>
[/php]