Created
November 5, 2025 13:52
-
-
Save easterncoder/d46051a0187aa1c8fa39937acf98b729 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| echo "Enter student name: "; | |
| $student_name = trim(fgets(STDIN)); | |
| for($i = 1; $i <= 5; $i++) { | |
| echo "Enter Answer #$i: "; | |
| $answer[] = trim(fgets(STDIN)); | |
| } | |
| $score = 0; | |
| foreach($answer as $value) { | |
| switch($value) { | |
| case 1: | |
| $score += 1; | |
| break; | |
| case 2: | |
| $score += 2; | |
| break; | |
| case 3: | |
| $score += 3; | |
| break; | |
| case 4: | |
| $score += 4; | |
| break; | |
| case 5: | |
| $score += 5; | |
| break; | |
| } | |
| } | |
| printf( | |
| "%s, your total score is %d and your average score is %.2f\n", | |
| $student_name, | |
| $score, | |
| $score / 5 | |
| ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment