Write a program to check student grade based on marks
Description: Write a PHP program to find the grade of a student based on the marks, using the if-else statement.
Rules and hints:
- If marks are 60 or more, the grade is First Division.
- If marks are from 45 to 59, the grade is Second Division.
- If marks are from 33 to 44, the grade is Third Division.
- If marks are less than 33, the student is Fail.
PHP program to check the grade of a student
<?php
$marks = 72;
if ($marks >= 60) {
$grade = "First Division";
} elseif ($marks >= 45) {
$grade = "Second Division";
} elseif ($marks >= 33) {
$grade = "Third Division";
} else {
$grade = "Fail";
}
echo "Student grade: " . $grade;
?>
Output:
Tutorials Class - Output Window
Student grade: First Division
How it works
- PHP checks the conditions from top to bottom and runs only the first one that is true.
- So it is enough to write the lowest marks of each grade (60, 45, 33) in the conditions.
- Change $marks to 40 and 20 and run again to test the other grades.
Learn more about the similar topics:
| Tutorials |
|---|
| PHP Decision Making |
| Interview Questions & Answers |
|---|
| No Content Found. |