Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Re: Number Guessing Game

by Shaveta_Chawla (Sexton)
on Sep 24, 2012 at 07:11 UTC ( #995301=note: print w/replies, xml ) Need Help??

in reply to Number Guessing Game

my $random = int (rand(100)); $count = 0; while ($random != $choice) { print "enter your choice = "; $choice = <STDIN>; $count++; print "you entered= $choice"; if($choice == $random) { print "Bravo-------------------you win"; print "\nTotal number of counts= $count\n"; exit; } elsif ($choice gt $random) { print "\nyour choice is TOO High\n"; } else { print "\nyour choice is too low\n"; } print "\nto quit press q OR press enter to continue "; $value = <STDIN>; if($value eq "q\n") { print "Sorry!! you lost :-(\n"; print "\nTotal number of counts= $count\n"; exit; } }

Replies are listed 'Best First'.
Re^2: Number Guessing Game
by nemesdani (Friar) on Sep 24, 2012 at 07:44 UTC
    That's not gonna work. gt, eq, etc are for strings, not for numbers.

    I'm too lazy to be proud of being impatient.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (10)
As of 2017-09-26 17:44 GMT
Find Nodes?
    Voting Booth?
    During the recent solar eclipse, I:

    Results (296 votes). Check out past polls.