My next venture on my geekhood is LOOPS!! Dang those stupid things anyways, lol, all they do is ruin my chances of getting more difficult scripts to work :) I tried following help in the CB about going back to the earlier loop and to put this variable into who-knows-where but maybe if someone has time they can show me a pseudo-code.

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:

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"; }
That is the jist of what I am trying to do with my ugly, ugly script below.

#!/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!



"Age is nothing more than an inaccurate number bestowed upon us at birth as just another means for others to judge and classify us"

sulfericacid

In reply to Looped around my neck (help with my poor little loops!) by sulfericacid

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.