Martha's CIS 52 Lab #1 Exercise # 7

Lab #1 Exercise #7  Write an HTML form that prompts the user for his or her grade on three different tests. Grades range from 0 to 100. See index.php for further instructions.

**************************************************************

CODES:

<p>ANSWER:</p>
<?php
$test1 = $_POST['grade1'];
$test2 = $_POST['grade2'];
$test3 = $_POST['grade3'];
$total = $test1 + $test2 + $test3;
$average = ($total / 3);
if (!isset($_POST['submit'])) {
?>
<form action="<?php echo $PHP_SELF;?>" method="post">
<p>Grade test #1
<input type="text" size="4px" maxlength="3px" name="grade1" />
Grade test #2
<input type="text" size="4px" maxlength="3px" name="grade2" />
Grade test #3
<input type="text" size="4px" maxlength="3px" name="grade3" />
<input type="submit" value="Submit" name="submit" />
</p>
<p>Please enter your most recent scores on tests, using numbers between 0 and 100.
Then, press the Submit button to calculate your grade.</p>
</form>
<?php
} else {
echo (!is_numeric($test1)) ? "Please enter a legitimate grade score." : "You entered ".$test1.", "
.$test2.", and ".$test3.".<br >The total grade point was: ".$total.", and the average grade point was: "
.round($average).".<br />";
if (($average >90) && ($average < 100)) {
echo "<h1>Congratulations! You've got an 'A'!</h1>";
} elseif (($average>80) && ($average < 89)) {
echo "<h2>You got a B - Keep up the good work!</h2>";
} elseif (($average > 70) && ($average < 79)) {
echo "<h3>You got a C, which is just 'average'. Surely you can do better!</h3>";
} elseif (($average > 60) && ($average < 69)) {
echo "<h4>Whoops - you got a D. Get with the program!</h4>";
} elseif (($average > 0) && ($average < 59)) {
echo "<h5 style='color:red'>Too bad - you got an F, and ".strtoupper("You are flunking!!")
."</h5>";
} else {
echo "You did not follow directions!";
}
}
?>

**************************************************************

ANSWER:

Grade test #1 Grade test #2 Grade test #3

Please enter your most recent scores on tests, using numbers between 0 and 100. Then, press the Submit button to calculate your grade.