Skip to content

Instantly share code, notes, and snippets.

@easterncoder
Created November 5, 2025 13:52
Show Gist options
  • Select an option

  • Save easterncoder/d46051a0187aa1c8fa39937acf98b729 to your computer and use it in GitHub Desktop.

Select an option

Save easterncoder/d46051a0187aa1c8fa39937acf98b729 to your computer and use it in GitHub Desktop.
<?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