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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |