settingsAccountsettings
By using our mini forum, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy
Menusettings

Q: Grades - PHP Function Task

+2 votes

Write a function that receives a grade between 2.00 and 6.00and prints the corresponding grade in words:

  • 2.00 - 2.99 - "Fail"
  • 3.00 - 3.49 - "Poor"
  • 3.50 - 4.49 - "Good"
  • 4.50 - 5.49 - "Very good"
  • 5.50 - 6.00 - "Excellent"
asked in PHP category by user andrew

1 Answer

+1 vote

Here is my solution:

<?php

$grade = floatval(readline());
gradeInWords($grade);

function gradeInWords($grade) {

    switch ($grade) {
        case $grade <= 2.99:
            echo 'Fail';
            break;
        case $grade <= 3.49 && $grade > 2.99 :
            echo 'Poor';
            break;
        case $grade <= 4.49 && $grade > 3.49:
            echo 'Good';
            break;
        case $grade <= 5.49 && $grade > 4.49:
            echo 'Very good';
            break;
        default:
            echo 'Excellent';
    }
}

answered by user ak47seo
...