Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Re^4: Number Guessing Game

by randomhero1270 (Novice)
on Sep 23, 2012 at 18:17 UTC ( #995228=note: print w/replies, xml ) Need Help??

in reply to Re^3: Number Guessing Game
in thread Number Guessing Game

I made it stop guessing zero. I just don't really understand how to set a new minimum or maximum and have it still guess a random number. Updated code below

use strict; my ($number, $new_guess, $my_hint, @guesses); my $range = 9; my $count = 1; my $number = 1 + int rand 10; #min of 1 and high of 10, range does 0-g +iven 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 = ((1 + int rand 10); print "I guess: " . $new_guess . "\n"; print "High, low, or right?\n"; } elsif ($my_hint eq "high"){ $new_guess = (1 + int rand 10); 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++; }

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://995228]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (4)
As of 2018-01-19 02:07 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (215 votes). Check out past polls.