Skip to content

Instantly share code, notes, and snippets.

@easterncoder
Last active November 5, 2025 14:35
Show Gist options
  • Select an option

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

Select an option

Save easterncoder/1a14b362db54917ccb324d95dcb89d09 to your computer and use it in GitHub Desktop.
#include <stdio.h>
int main() {
char student_name[100];
int answer[5];
int score = 0;
int i;
int status;
printf("Enter student name: ");
scanf("%s", student_name);
for(i = 1; i <= 5; i++) {
printf("Enter Answer #%d: ", i);
status = scanf("%d", &answer[i-1]);
if(status < 1) {
int ch;
while ((ch = getchar()) != '\n' && ch != EOF) {
; // discard the rest of the line
}
}
}
for(i = 0; i < 5; i++) {
switch(answer[i]) {
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.0);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment