Perl-Sensitive Sunglasses PerlMonks

### Re: Average/mean calculator

by Laurent_R (Abbot)
 on Jun 04, 2014 at 18:03 UTC ( #1088707=note: print w/replies, xml ) Need Help??

Hi, store your numbers in an array or update the sum and count as you go, then you only need to divide by the count. Something like this:
```print "In this version you can use up to TEN NUMBERS! \n";
print "when you have entered the numbers you need type 'end' \n";
my \$count = 1;
my \$total = 0;

while (\$count <= 10) {
print "Enter number \$count ";
my \$num = <STDIN>;
chomp \$num;
last if \$num eq "end";
\$total += \$num;
\$count++;
}
print " Average is: ", \$total / \$count, "\n";

Replies are listed 'Best First'.
Re^2: Average/mean calculator
by Paradizingmania (Initiate) on Jun 04, 2014 at 18:54 UTC

hey 3 questions, first what does the <= mean second what does the line \$total += \$num; and last what does the \$count++ mean, i am still new to this so keep that in mind, and thanks for the help

You should read the perlop documentation, it describes what all the operators are. Having said that:

• \$a <= \$b means "\$a is less than or equal to \$b"
• \$total += \$num means the same as \$total = \$total + \$num
• \$count++ means the same as \$count = \$count+1

...roboticus

When your only tool is a hammer, all problems look like your thumb.

Roboticus has given you the answers to your questions, but I should stress these questions relate to really basic Perl operators, and that you should absolutely take a serious look at the documentation pointed by him in his answer (perlop). Also take a look at the documentation pointed out by toolic, especially perlintro.

Create A New User
Node Status?
node history
Node Type: note [id://1088707]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (6)
As of 2017-08-20 17:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
Who is your favorite scientist and why?

Results (317 votes). Check out past polls.

Notices?