Loading ...
Sorry, an error occurred while loading the content.

Re: [PBML] illegal division by zero on line 14?

Expand Messages
  • Donald Korrecta
    I ll stick my neck out here and ask; in your lib file, how do you increment an uninitialized variable? ... From: fast.linux Subject:
    Message 1 of 3 , Sep 22, 2008
    • 0 Attachment
      I'll stick my neck out here and ask; in your lib file, how do you increment an uninitialized variable?

      --- On Tue, 9/16/08, fast.linux <fast.linux@...> wrote:
      From: fast.linux <fast.linux@...>
      Subject: [PBML] illegal division by zero on line 14?
      To: perl-beginner@yahoogroups.com
      Date: Tuesday, September 16, 2008, 10:44 PM











      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-1.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(@functionArra y){



      $functionSum += $line;



      $count++



      }



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



      }



      1;



      #_END_





























      [Non-text portions of this message have been removed]
    Your message has been successfully submitted and would be delivered to recipients shortly.