Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

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++; }

In reply to Re^4: Number Guessing Game by randomhero1270
in thread Number Guessing Game by randomhero1270

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others avoiding work at the Monastery: (4)
    As of 2018-07-19 23:48 GMT
    Find Nodes?
      Voting Booth?
      It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?

      Results (421 votes). Check out past polls.