in reply to Re: Number Guessing Game
in thread Number Guessing Game
I fixed the counter so now it works. My questions are, how do I make it actually guess higher when I type "low" or guess lower when I type "high" and why does it still guess 0? Here is my updated code
use strict; my ($number, $new_guess, $my_hint, @guesses); my $range = 9; my $count = 1; $number = int(rand($range)); #min of 1 and high of 10, range does 0-gi +ven int so i made the range 9 (0-9) and added one to it -> (1-10) print "My guess is: $number \n"; print "High, low, or right?\n"; while($my_hint ne "right"){ chomp($my_hint = <STDIN>); @guesses[$count] = $my_hint; if ($my_hint eq "low"){ $new_guess = int(rand($number)); print "I guess: " . $new_guess . "\n"; print "High, low, or right?\n"; } elsif ($my_hint eq "high"){ $new_guess = int(rand($number)); print "I guess: " . $new_guess . "\n"; print "High, low, or right?\n"; } elsif ($my_hint eq "right"){ print "It took me " . $count . " tries\n"; } else{ print "What? Am I high, low, or right?\n"; } $count++; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Number Guessing Game
by roboticus (Chancellor) on Sep 23, 2012 at 17:47 UTC | |
by randomhero1270 (Novice) on Sep 23, 2012 at 18:17 UTC | |
by randomhero1270 (Novice) on Sep 23, 2012 at 17:57 UTC | |
by roboticus (Chancellor) on Sep 23, 2012 at 19:24 UTC |