Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^2: Guess That Number

by naildownx (Beadle)
on Jul 09, 2009 at 19:38 UTC ( [id://778680]=note: print w/replies, xml ) Need Help??


in reply to Re: Guess That Number
in thread Guess That Number

toolic For a reason I haven't discovered yet, when I change it to D and remove the + sign it won't receive any number...can you get the same results?
The early bird gets the worm but the second mouse gets the cheese.
pretendeavor

Replies are listed 'Best First'.
Re^3: Guess That Number
by toolic (Bishop) on Jul 09, 2009 at 20:09 UTC
    When you update your original node, you should leave a note that you did so, and more importantly, you should first test that your updated code works.

    Here is the code that works for me. Note that it does not have jdporter's bug fix.

    use strict; use warnings; my $low = 1; #Current low limit my $high = 1000; #Current high limit #This is the secret number...Add one because we #don't need to wind up with a zero now do we? my $goal = int(rand($high))+1; while (1) { print "Enter a number between $low and $high: "; #The answer from the user my $answer = <STDIN>; chomp($answer); if ($answer =~ /\D/) { print "Please enter a number only\n"; next; } if ($answer == $goal) { print "Holy cow! You guessed it!\n"; exit; } if (($answer < $low) || ($answer > $high)) { print "Please stay between $low and $high.\n"; next; } if ($answer < $goal) { $low = $answer; } else { $high = $answer; } }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2024-04-25 16:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found