[Oc-pm] illegal division by zero?

Raul Ruiz Jr. fast.linux at yahoo.com
Tue Sep 16 22:20:49 PDT 2008


I have a question? My instructor did not pass me on my script/library project because of "illegal division by zero on line 14 of obj13-lib.pl (my library) part of my script. 
What am I doing wrong and can someone help me? 

I would really appreciate help with this.

 I thought I got this correct.

This is a description of my project goal, and below is my graded script.:

Write a script called obj13-1.pl and a library called
obj13-lib.pl.  The library should contain a function that takes
in an array of numbers (of arbitrary size).  The function will then
calculate the average of the numbers, the total of all of the numbers
added together, and a new array of numbers which is comprised of the other numbers
divided by 2.

Objective:

See Project Page.
Here are the contents of the file you handed in:

Script output:
-------------------------------
Illegal division by zero at obj13-lib.pl line 14.

-------------------------------
Script obj13.pl contents:
-------------------------------
#!/usr/bin/perl

require 'obj13-lib.pl';

while()

{

    chomp;
    last if ! /\d/;

    push(@userArray,$_);
}

($sum,$avg) = &sumIt(@userArray);

print "Total:$sum\nAverage:$avg\n";

#_END_


Overall Comments:

Good!  What about the new array that is created using the original array elements, divided by 2?


My library script obj13-lib.pl below:

#!/usr/bin/perl 

sub sumIt {

 @functionArray = @_;

 foreach $line(@functionArray){

 $functionSum += $line;

 $count++

       }

return ($functionSum,$functionSum / $count);

}

1;


#_END_




      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/oc-pm/attachments/20080916/d1b3d054/attachment.html>


More information about the Oc-pm mailing list