Perl- Grading Program Help

Discussion in 'Perl' started by Shawn09, Feb 24, 2010.

  1. Shawn09

    Shawn09 New Member

    Joined:
    Feb 24, 2010
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    Im having troubles with my code and I cant seem to figure out whats wrong im sure its easy for you since im new to perl and i mean New New.

    Code:


    Code:
    <html>
    <body bgcolor=gray>
    <center><b><head>Average your Grades</head></b></center><br>
    <center><form action=/cgi-bin/pretask1.cgi method=post>
    Grade 1 <input type=text size=3 name=grade1 maxlength=3><br>
    Grade 2 <input type=text size=3 name=grade2 maxlength=3><br>
    Grade 3 <input type=text size=3 name=grade3 maxlength=3><br>
    Grade 4 <input type=text size=3 name=grade4 maxlength=3><br>
    Grade 5 <input type=text size=3 name=grade5 maxlength=3><br>
    <br>
    <input type=submit>
    </body>
    </center>
    </form>
    </html>

    #!/usr/bin/perl
    $count=0;
    print "Content-type:text/html\n\n";
    use CGI ':standard';

    $grade1=param('grade1');
    $grade2=param('grade2');
    $grade3=param('grade3');
    $grade4=param('grade4');
    $grade5=param('grade5');

    @array=($grade1,$grade2,$grade3,$grade4,$grade5);
    foreach $grade(@array){

    print "$grade<br>";
    if(($grade !=NULL)||($grade eq 0)){
    $count++;
    $total=$grade+$total;
    }


    }

    $average=$total/$count;
    print "$count"<br>
    Total of Grades Entered:$total
    Average Grade So Far:$average";


    Now with this grading program when I hit submit just the list of grades show up I need it to actually show how many grades I have entered and the average of all the grades. Any help will be appreciated.
     
  2. Shawn09

    Shawn09 New Member

    Joined:
    Feb 24, 2010
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    Nobody able to help?
     
  3. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    I am not a PERL expert but I cannot see you printing the average.
     
  4. Shawn09

    Shawn09 New Member

    Joined:
    Feb 24, 2010
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    What do I have to change?
     
  5. DrBeaker

    DrBeaker New Member

    Joined:
    Mar 2, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    I think this will work...it did so in my Perl editor. I cleaned up the print command at the end.
    Code:
    #!/usr/bin/perl
    
    $count=0;
    print "Content-type:text/html\n\n";
    use CGI ':standard';
    
    #$grade1=param('grade1');
    #$grade2=param('grade2');
    #$grade3=param('grade3');
    #$grade4=param('grade4');
    #$grade5=param('grade5');
    
    
    @array=($grade1,$grade2,$grade3,$grade4,$grade5);
    foreach $grade(@array){
    
    print "$grade<br>";
    if(($grade !=NULL)||($grade eq 0)){
    $count++;
    $total=$grade+$total;
    }
    
    
    }
    print "<p>";
    $average=$total/$count;
    print "Number entered: $count<br>Total of Grades Entered: $total<br>Average Grade So Far: $average";
     
    Last edited by a moderator: Mar 2, 2010

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice