Phoenix216
11-03-2006, 11:14 PM
I am supposed to make a guessing game for my programming class. I got the first part which was to have the computer select a random number and then have the computer guess the number outputting each number guessed and if it was too high or too low. The second part is to reset the lower range to drone's guess + 1 and the upper range to drone's guess - 1 and then output the updated range.
I'm afraid I'm completely lost and since this is an online course it's hard to ask the professor for help. Could any of you look at my code and steer me in the right direction? I'd really appreciate any hints.
print "***** Version - 2 Game *****<br>";
random(10,25,&$myNumber);
print "I will pick a number between 10 and 25 - how long will the drone take to guess?<br>";
print "My number is $myNumber.<br>";
$keepGuessing = start;
$attempt = 0;
while ($keepGuessing==start)
{
random(10,25,&$droneGuess);
print "Drone selects $droneGuess<br>";
if($droneGuess == $myNumber )
{
$keepGuessing =stop;
}
elseif($droneGuess<$myNumber)
{
$keepGuessing = start;
$low=$num-1;
$high=$high;
print "Your guess is too low<br>";
print "....new range is $low.... $high<br>";
}
else
{
$keepGuessing = start;
$high=$num+1;
$low=$low;
print "Your guess is too high<br>";
print "....new range is $low.... $high<br>";
}
$attempt= $attempt + 1;
}
print "******You needed $attempt tries to guess my number******<br>";
return;
function random($low,$high,$num){$range = $high - $low + 1;$num = rand() % $range + $low;}
I'm afraid I'm completely lost and since this is an online course it's hard to ask the professor for help. Could any of you look at my code and steer me in the right direction? I'd really appreciate any hints.
print "***** Version - 2 Game *****<br>";
random(10,25,&$myNumber);
print "I will pick a number between 10 and 25 - how long will the drone take to guess?<br>";
print "My number is $myNumber.<br>";
$keepGuessing = start;
$attempt = 0;
while ($keepGuessing==start)
{
random(10,25,&$droneGuess);
print "Drone selects $droneGuess<br>";
if($droneGuess == $myNumber )
{
$keepGuessing =stop;
}
elseif($droneGuess<$myNumber)
{
$keepGuessing = start;
$low=$num-1;
$high=$high;
print "Your guess is too low<br>";
print "....new range is $low.... $high<br>";
}
else
{
$keepGuessing = start;
$high=$num+1;
$low=$low;
print "Your guess is too high<br>";
print "....new range is $low.... $high<br>";
}
$attempt= $attempt + 1;
}
print "******You needed $attempt tries to guess my number******<br>";
return;
function random($low,$high,$num){$range = $high - $low + 1;$num = rand() % $range + $low;}