hey, i am a beginner to perl and programing in general, and i made a calculator that calculates the average of numbers, and i was just wondering if there was any shorter or easier way to do it.

print "In this version you can use up to TEN NUMBERS! \n"; print "when you have entered the numbers you need type 'end' \n"; print "Enter number 1 "; my $num1 = <STDIN>; print "Enter number 2 "; my $num2 = <STDIN>; print "Enter number 3 "; my $num3 = <STDIN>; if ($num3 =~ /^[+-]?\d+$/ ) { print "Enter number 4 "; my $num4 = <STDIN>; if ($num4 =~ /^[+-]?\d+$/ ) { print "Enter number 5 "; my $num5 = <STDIN>; if ($num5 =~ /^[+-]?\d+$/ ) { print "Enter number 6 "; my $num6 = <STDIN>; if ($num6 =~ /^[+-]?\d+$/ ) { print "Enter number 7 "; my $num7 = <STDIN>; if ($num7 =~ /^[+-]?\d+$/ ) { print "Enter number 8 "; my $num8 = <STDIN>; if ($num8 =~ /^[+-]?\d+$/ ) { print "Enter number 9 "; my $num9 = <STDIN>; if ($num9 =~ /^[+-]?\d+$/ ) { print "Enter number 10 "; my $num10 = <STDIN>; if ($num10 =~ /^[+-]?\d+$/ ) { print "Your answer is " . (($num1+ +$num2+$num3+$num4+$num4+$num5+$num6+$num7+$num8+$num9+$num10)/10) . " +\n"; } else { print "Your answer is " . (($num1+ +$num2+$num3+$num4+$num5+$num6+$num7+$num8+$num9)/9) . "\n"; } } else { print "Your answer is " . (($num1+$num +2+$num3+$num4+$num5+$num6+$num7+$num8)/8) . "\n"; } } else { print "Your answer is " . (($num1+$num2+$n +um3+$num4+$num5+$num6+$num7)/7) . "\n"; } } else { print "Your answer is " . (($num1+$num2+$num3+ +$num4+$num5+$num6)/6) . "\n"; } } else { print "Your answer is " . (($num1+$num2+$num3+$num +4+$$num5)/5) . "\n"; } } else { print "Your answer is " . (($num1+$num2+$num3+$num4)/4) . +"\n"; } } else { print "Your answer is " . (($num1+$num2+$num3)/3) . "\n"; } } else { print "Your answer is " . (($num1+$num2)/2) . "\n"; }

oh and i have not really been able to find any got tutorials so if you could link any that would be great. thanks in advance


In reply to Average/mean calculator by Paradizingmania

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.