Hello everybody, I just joined and also this is my very first perl script. I had made one similar, but using qbasic about 20 years ago, since I only use linux now, perl seems like a more convenient option, and so far I really like it (perl). I had to of course read some tutorials, but never did find anything really with something like this, so I took what I could understand and put this together, it is a math program that give random multiplication problems, to help someone memorize the basic times tables 1 through 10. These days with modern calculators, etc. that might not seem important, but for simple multiplication it is faster when one can do it in their head, from memory. Any way this is what I came up with, I am happy with it except 1 thing, which I will get to, first the code (script)

#!/usr/bin/perl print "Type in the correct answer, \n"; print "Hit enter key to continue, if it is not correct\n "; print "the program will not move on to a new problem, \n "; print "think about your answer, and try again, when it is\n "; print "the correct answer, it will tell you, \n "; print "and give a new problem.\n "; for( ; ; ) { my $random = int rand 11; my $random2 = int rand 11; print "$random x $random2 = "; $x = $random * $random2; while ( $answer ne "$x" ) { $answer = <STDIN>; chomp $answer; ; } if ( $answer eq "$x" ) { } print "Great $answer is correct.\n"; print "hit enter to continue, ctr-c to exit."; $_ = <STDIN>; print "\033[2J"; #print "\033[2J"Might not work on some systems but it does on mine }

The one thing, I have not been able to get right, I would like it to give out put and say "sorry XX is not correct,please try again" XX= the number that was entered, so any way I would like it to say that if when a incorrect answer is given. I tried various things but they either displayed the previous answer from the previous problem, or caused the script to not work. I am kind of "stumped on that. More study on tutorials and I may eventually figure it out. Any way, I wanted to share my first perl script, and introduce myself, so that is about the only question I have at this point. Thanks for any feed back.


In reply to Basic Times Table excercise by jibberjabber

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.