fork download
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. int main() {
  5. char answer[50];
  6. int score = 0;
  7.  
  8. printf("Welcome to the Football Quiz!\n");
  9. printf("You will be asked 3 questions. Each correct answer gives you 1 point.\n\n");
  10.  
  11. // Question 1
  12. printf("Question 1: Who won the FIFA World Cup in 2018?\n");
  13. printf("Your answer: ");
  14. fgets(answer, sizeof(answer), stdin);
  15. answer[strcspn(answer, "\n")] = 0; // Remove newline character
  16.  
  17. if (strcasecmp(answer, "France") == 0) {
  18. printf("Correct!\n");
  19. score++;
  20. } else {
  21. printf("Wrong! The correct answer is France.\n");
  22. }
  23.  
  24. // Question 2
  25. printf("\nQuestion 2: Which player has won the most Ballon d'Or awards?\n");
  26. printf("Your answer: ");
  27. fgets(answer, sizeof(answer), stdin);
  28. answer[strcspn(answer, "\n")] = 0;
  29.  
  30. if (strcasecmp(answer, "Lionel Messi") == 0 || strcasecmp(answer, "Messi") == 0) {
  31. printf("Correct!\n");
  32. score++;
  33. } else {
  34. printf("Wrong! The correct answer is Lionel Messi.\n");
  35. }
  36.  
  37. // Question 3
  38. printf("\nQuestion 3: What is the name of the stadium where Manchester United plays?\n");
  39. printf("Your answer: ");
  40. fgets(answer, sizeof(answer), stdin);
  41. answer[strcspn(answer, "\n")] = 0;
  42.  
  43. if (strcasecmp(answer, "Old Trafford") == 0) {
  44. printf("Correct!\n");
  45. score++;
  46. } else {
  47. printf("Wrong! The correct answer is Old Trafford.\n");
  48. }
  49.  
  50. // Final Score
  51. printf("\nYour final score is: %d out of 3\n", score);
  52.  
  53. if (score == 3) {
  54. printf("Congratulations! You're a football expert!\n");
  55. } else if (score == 2) {
  56. printf("Well done! You know a lot about football.\n");
  57. } else if (score == 1) {
  58. printf("Good try! But you can improve your football knowledge.\n");
  59. } else {
  60. printf("Better luck next time!\n");
  61. }
  62.  
  63. return 0;
  64. }
Success #stdin #stdout 0s 5284KB
stdin
Standard input is empty
stdout
Welcome to the Football Quiz!
You will be asked 3 questions. Each correct answer gives you 1 point.

Question 1: Who won the FIFA World Cup in 2018?
Your answer: Wrong! The correct answer is France.

Question 2: Which player has won the most Ballon d'Or awards?
Your answer: Wrong! The correct answer is Lionel Messi.

Question 3: What is the name of the stadium where Manchester United plays?
Your answer: Wrong! The correct answer is Old Trafford.

Your final score is: 0 out of 3
Better luck next time!