I am doing the guess a number game I have it running correctly the only thing I can not figure out is how to track the numbers guessed. It is suppose to keep track of the numbers the user guess and print an error message if they guess the same number more than once. This is what I have so far:

do { @numbers=(1..10); $index=int (rand (10)); $rannumber="$numbers[$index]\n"; game($rannumber); print "Would you like to play again(Y or N) "; do { chomp($answer=<STDIN>); $answer=uc($answer); if (($answer ne "Y") and ($answer ne "N")){ print "Invalid entry - PLEASE SELECT Y OR N\n"; } }while (($answer ne "Y") and ($answer ne "N")); } until ($answer eq "N"); sub game { my $rannumber=@_[0]; print "Guess a number between (1-10) "; do { my $guess=<STDIN>; @allguess=$guess; $track = grep(!/1..10/, $allguess); if ($track = $allguess) { print "Same guess try again\n"; } if ($guess > 10) { print "Invalid entry - Guess Again\n"; } elsif ($guess < 1) { print "Invalid entry - Guess Again\n"; } elsif ($guess == $rannumber) { print "You Win\n";} else {print "Guess Again\n";} } until ($guess == $rannumber); return; }

In reply to Help with Guessing Game by dj_jodo

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.