Perl- Grading Program Help

Shawn09's Avatar
Newbie Member
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.
0
Shawn09's Avatar
Newbie Member
Nobody able to help?
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
I am not a PERL expert but I cannot see you printing the average.
0
Shawn09's Avatar
Newbie Member
What do I have to change?
0
DrBeaker's Avatar
Newbie Member
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 shabbir; 2Mar2010 at 12:53.. Reason: Code blocks