Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Number Guessing Game

by Shaveta_Chawla (Acolyte)
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; } }


Comment on Re: Number Guessing Game
Download Code
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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://995301]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (11)
As of 2014-11-26 09:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (165 votes), past polls