# PHP Script to Calculate Total Marks of Student and Display Grade

__PHP__ script to calculate total marks of student and display grade.

In this article, you will learn how to write PHP script to calculate total marks of student and display grade.

### Example

**The Total marks = 371/500**

The Average marks = 74.2

The Percentage = 74.2%

The Grade = 'C'The Average marks = 74.2

The Percentage = 74.2%

The Grade = 'C'

### Standard Formula

**Total = p + c + m + e + h**

**Average = total / 5.0**

**Percentage = (total / 500.0) * 100**

Source Code

```
<?php
// PHP Script to Calculate Total Marks of Student and Display Grade
// These are the marks of five subjects
$sub_1 = 95;
$sub_2 = 85;
$sub_3 = 74;
$sub_4 = 64;
$sub_5 = 53;
$total = NULL;
$average = NULL;
$percentage = NULL;
$grade = NULL;
// 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

`The Total marks = 371/500`

The Average marks = 74.2

The Percentage = 74.2%

The Grade = 'C'

### Explanation

**Average:** we take the marks of five subjects as input after that the sum of these marks is divided by

then It will return the average value of the marks.**5**

**Percentage:** we made a division of the sum of user's marks by

then It multiplied by **500**

then It will return the percentage value of the marks.**100**

**Grade:** we compared the value of the Average marks with these range of marks to find the Grade of students like:

If `Average marks >= 90`

then It's Grade is **'A'**

If `Average marks >= 80 and < 90`

then It's Grade is **'B'**

If `Average marks >= 70 and < 80`

then It's Grade is **'C'**

If `Average marks >= 60 and < 70`

then It's Grade is **'D'**

If `Average marks < 60`

then It's Grade is **'E'**

#### Also, visit these links

**C Program to Calculate Percentage and Grade**

**C++ Program to Calculate Sum of 5 Subjects and Find Percentage and Grade**

**Java Program to Enter Marks of Five Subjects and Calculate Total, Percentage, and Grade**

**Python Program to Calculate Total Marks Percentage and Grade of a Student**