@InspiredPrynce Your code is working as expected. 49.98 is greater than 49, so doesn’t qualify as a ‘D’ grade.
You have cases for a grade less than and equal to 49, and equal or greater than 50, but nothing for a number between 49 and 50, which is why 49.98 falls all the way through to your else case.
Instead, consider checking the score against an array of grade boundaries and return the grade if the value satisfies one. If not, return ‘F’ by default:
$boundaries = [
'A' => 70,
'B' => 60,
'C' => 50,
'D' => 45,
'E' => 40,
];
foreach ($boundaries as $grade => $threshold) {
if ($score >= $threshold) {
return $grade;
}
}
return 'F';