You have DECLARED your subroutines, but not CALLEd them.

The code works if you add the calls around the "$average" caclulation, like:

div(); # CALL the sub named div $average=($g1 + $g2 + $g3 + $g4 + $g5 + $g6) / $div; letter(); #CALL the sub named letter
Of course, as others have pointed out, there is much room for code and coding style improvement.

Update:Here is a more concise, and idomatic version:

#!/usr/bin/perl use strict; use CGI qw|:standard|; my ($count,$total); my @gradeletter = qw| A A- B+ B B- C+ C C- D+ D |; # no F because that + is default; my @gradeval = qw|92.5 89.5 87.5 82.5 79.5 76.5 72.5 69.5 66.5 62.5 |; for(1..6){ my $value = param ("g$_"); $count++ if $value > 0; $total += $value; } $count ||=1; # Avoid divide by zero my $average = $total / $count; my $letter = "F"; # Default , unless a better one is found for (0..$#gradeletter){ if ($average > $gradeval[$_]){ $letter = $gradeletter[$_]; last; } } $letter = "INVALID" if $average > 100; print ul(li(" The letter grade is $letter" )), "\n";

     Syntactic sugar causes cancer of the semicolon.        --Alan Perlis


In reply to Re: grade calulator coding problem by NetWallah
in thread grade calulator coding problem by friar tux

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.