#Guessing Game #You only get 10 tries! #Gives the option of starting over. #This version should count your turns for you, down from #ten. TOP: my $tries = 10; #This is how many guesses you get. my $value = int(rand(200)); #This is the number they have to guess: a random integer. print "Pick a number between 0 and 200.\n"; print "You have "; print $tries; print " guesses left.\n"; $tries--; my $guess = <STDIN>; until ($tries==0){ if($guess>$value){ print "You need to guess a lower number.\n"; print "Guesses left: "; print $tries; print "\n"; $tries--; $guess = <STDIN>; }elsif($guess<$value){ print "You need to guess a higher number.\n"; print "Guesses left: "; print $tries; print "\n"; $tries--; $guess = <STDIN>; }else{ print "You guessed my number in "; print (10-$tries); print " guesses. Thanks for playing. \n"; $tries=0} } if ($guess != $value){ print "Sorry, you ran out of guesses. My number was "; print $value; print ". \n"; } print "Play Again? (y/n) \n"; my $again = <STDIN>; chomp ($again); if($again eq "y"){ goto TOP; }else{ print "Goodbye!"; }

In reply to 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.