Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Perl (http://www.go4expert.com/forums/perl/)
-   -   Perl- Grading Program Help (http://www.go4expert.com/forums/perl-grading-program-help-t21101/)

Shawn09 25Feb2010 00:28

Perl- Grading Program Help
 
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.

Shawn09 25Feb2010 04:18

Re: Perl- Grading Program Help
 
Nobody able to help?

shabbir 25Feb2010 10:35

Re: Perl- Grading Program Help
 
I am not a PERL expert but I cannot see you printing the average.

Shawn09 26Feb2010 07:11

Re: Perl- Grading Program Help
 
What do I have to change?

DrBeaker 2Mar2010 06:10

Re: Perl- Grading Program Help
 
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";



All times are GMT +5.5. The time now is 17:07.