PHP Online Compiler
Example: PHP Program to Find Grade of a Student using Nested If-else
C
C++
C#
Java
Python
PHP
main.php
STDIN
Run
<?php // PHP Program to Find Grade of a Student using Nested If-else // These are the marks of five subjects $sub_1 = 85; $sub_2 = 54; $sub_3 = 74; $sub_4 = 49; $sub_5 = 38; // It will calculate total, average, percentage, and grade $total = $sub_1 + $sub_2 + $sub_3 + $sub_4 + $sub_5; $average = $total / 5.0; $percentage = ($total / 500.0) * 100; if ($average >= 90) $grade = "A"; else { if ($average >= 80 && $average < 90) $grade = "B"; else { if ($average >= 70 && $average < 80) $grade = "C"; else { if ($average >= 60 && $average < 70) $grade = "D"; else $grade = "E"; } } } // It will print the final output echo "The Total marks = " . $total . "/500\n"; echo "The Average marks = " . $average . "\n"; echo "The Percentage = " . $percentage . "%\n"; echo "The Grade = '" . $grade . "'\n"; ?>
Output
Clear
ADVERTISEMENTS