Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

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
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 the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (11)
As of 2015-11-30 19:31 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (778 votes), past polls