in reply to Re: Weighted averages
in thread Weighted averages

I feel like this is a stupid question, but what part of the while loop is allowing it to know to start a new group. Student, quize,exam, final. How does it go about starting with student again? In constant student is set to zero, but the second student is in the 7th index and not 0. Maybe I am just not understanding how that works. My second question is about running that through a subroutine. If I wanted to run the quizes through my quiz subrotuine would it be as simple as:

sub quiz { return (sum(@fields[FIRST_QUIZ..LAST_QUIZ])/ 300) * .10; }

Ultimately I am trying to find the final grades for each student.

Replies are listed 'Best First'.
Re^3: Weighted averages
by Eily (Monsignor) on Jan 25, 2018 at 17:40 UTC

    The data is read line by line. So each new line you get a new iteration of the loop, a new array, which starts at 0 again.

    Using my code and your sub, you could just write: say "Weighted average: ", quiz(@fields[FIRST_QUIZ..LAST_QUIZ]) + exam(@fields[FIRST_EXAM..LAST_EXAM]) + final($fields[FINAL])

      Ah yes, that makes sense. Ok I am going to go and mess around with that a bit. Thanks for the help.