I don't want anyone to fix this script, that's sorta what I want to achieve otherwise I can't call it my own. Can someone show me the right method to do say something like:
That is the jist of what I am trying to do with my ugly, ugly script below.if (($a != b) && ($error > 0 && $error <= 3 )) { repeat question and <STDIN> increment $error++ } if ($a == $b) { print "Correct!\n" print "Only took you $error times!\n"; } if ($error >= 3) { print "Took you too many tries, you lose\n"; }
#!/usr/bin/perl use strict; use warnings; print "Enter the max number:\n"; chomp(my $maxguess = <STDIN>); $maxguess =~s/\r//; my $range = rand($maxguess + 1)%10; my $numguess = 0; my $tries = 3; print "What is your guess?\n"; chomp(my $guess = <STDIN>); $guess =~s/\r//; $numguess++; # print "Guess: $guess\n"; # print "Range: $range\n"; until ($numguess > 0 && $numguess >= $tries) { #print "this should work\n"; &guessing; $numguess++; if ($numguess >= $maxguess) { print "You lose!\n"; } } sub guessing{ while ($guess != $range){ print "Wrong answer! Please try again!\n"; print "Guess: \n"; chomp(my $guess = <STDIN>); print "Guess #: $numguess\n"; print "Max # : $maxguess\n"; print "Answer : $range\n\n\n\n"; if ($guess == $range) { print "You win!\n"; exit; } last; } } if ($numguess >= $maxguess) { print "You lose!\n"; } elsif ($guess == $range) { print "You win!\n"; print "It only took you $numguess time(s)!!\n"; }
Again, I'm just looking on how to get the loops setup, I don't need anyone debugging the script (Gadz knows that would take you weeks). Thanks so much for your help!
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |