Here is the initial code
use warnings; use strict; print "Welcome to Multiplication Challenge\n"; print "What would you like to do?\n"; print "1) FLASHCARD MODE\n"; print "2) TEST MODE\n"; print "3) OPTIONS\n"; print "4) Exit\n"; my $input = undef; my $max = undef; my $min = 10; sub menu { print "What would you like to do?\n"; print "1) FLASHCARD MODE\n"; print "2) TEST MODE\n"; print "3) OPTIONS\n"; print "4) Exit\n"; } while ( $input = (<STDIN>) ) { if ( $input =~ /1/ ) { print "FLASHCARD MODE\n"; flashcard(); } elsif ( $input =~ /2/ ) { print "TEST MODE\n"; testmode(); } elsif ( $input =~ /3/ ) { print "3\n"; print "What is the maximum number?\n"; my $max = (<STDIN>); &makeitbig($max); &menu(); } elsif ( $input =~ /4/ ) { really(); } } sub really { print "Are you sure?\n"; my $input = (<STDIN>); if ( $input =~ /y/ ) { exit; } else { menu(); } } sub flashcard { for ( 1 .. 10 ) { my $random1 = int( rand(10) ); my $random2 = int( rand(10) ); print "$random1 * $random2\n"; my $total = ( $random1 * $random2 ); &validate($total); } } my $count = 1; sub validate { my $newdata = shift; TRYAGAIN: my $input = (<STDIN>); if ( $input == $newdata ) { print "Correct!\n"; $count++; if ( $count == 10 ) { print "Congratulations\n"; print "You have finished FLASHCARD MODE;\n"; menu(); } } else { print "$count: Try again\n"; goto TRYAGAIN; } } sub testmode { for ( 1 .. 25 ) { my $random1 = int( rand(10) ); my $random2 = int( rand(10) ); print "Problem '#'$_\n"; print "$random1 * $random2\n"; my $total = ( $random1 * $random2 ); &validate_low($total); } } my $meter = 1; my @correct = (); my $correctanswer = 1; sub validate_low { my $newdata = shift; my $input = (<STDIN>); $meter++; if ( $input == $newdata ) { print "Correct!\n"; push( @correct, $correctanswer ); } else { print "Sorry!\n"; } if ( $meter == 25 ) { &calculate(); } } my $sum = 0; sub calculate { foreach (@correct) { $sum += $_; return $sum; } my $prcnt = 4 * $sum; print "You got $sum answers correctly out of 25. This is $prcnt%\n +"; } sub makeitbig { my $other = shift; if ( $other == $min ) { return $min; } else { return $other; } }

In reply to Re^2: Re-assign value to subroutine by props
in thread Re-assign value to subroutine by props

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.