Wow, truly the monks are wise and patient. Thanks for the great advice.

Yes, I had some sense that goto might be a little hacky, but I didn't know how to use subroutines. Obviously, they are the magic answer I needed. Also, I did use strict and use warnings while I was working on this, but after I knew it would work, I didn't bother pasting them in here--why? Who knows; however, I now see the error of my ways.

Looking at your for loop, I have a question. How does this handle the situation in which the player does successfully guess the answer in under ten tries? Since you have set the loop to run ten times, it looks like it will print "you have x guesses left" and wait for guess input even after you have won the game. I have just run the code and seen that this is not the case, but I can't figure out why. (Also, it looks like the "guesses left" line needs to be removed from the if statements, since you have put it at the top of the for loop. But this is a simple matter.)

Here is another question: why do I have to chomp $again, but not chomp $guess?


In reply to Re^2: Number Guess by cryptoquip
in thread Number Guess by cryptoquip

Title:
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, details, 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, summary, 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.