-
Notifications
You must be signed in to change notification settings - Fork 5
/
trivia.c
42 lines (34 loc) · 1.05 KB
/
trivia.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <stdio.h>
#include <string.h>
#define NUM_QUESTIONS 3
#define QUESTION_LENGTH 100
#define ANSWER_LENGTH 20
int main() {
char questions[NUM_QUESTIONS][QUESTION_LENGTH] = {
"What is the capital of France?",
"What is the largest planet in our solar system?",
"Who is r3dhulk?"
};
char answers[NUM_QUESTIONS][ANSWER_LENGTH] = {
"Paris",
"Jupiter",
"Sumalya"
};
char userAnswer[ANSWER_LENGTH];
int score = 0;
printf("Welcome to the trivia game!\n");
for (int i = 0; i < NUM_QUESTIONS; i++) {
printf("\nQuestion %d: %s\n", i+1, questions[i]);
printf("Enter your answer: ");
scanf("%s", userAnswer);
if (strcmp(userAnswer, answers[i]) == 0) {
printf("Correct!\n");
score++;
} else {
printf("Incorrect. The correct answer is %s\n", answers[i]);
}
}
printf("\nCongratulations, you finished the trivia game!\n");
printf("Your final score is %d/%d\n", score, NUM_QUESTIONS);
return 0;
}