-
Notifications
You must be signed in to change notification settings - Fork 93
/
Copy pathQuiz.c
54 lines (43 loc) · 1.4 KB
/
Quiz.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
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <stdio.h>
#include <ctype.h>
int main()
{
char questions[][100] = {"1. What year did the C language debut?: ",
"2. Who is credited with creating C?:",
"3. What is the predecessor of C?: "};
char options[][100] = {"A. 1969", "B. 1972", "C. 1975", "D. 1999",
"A. Dennis Ritchie", "B. Nikola Tesla", "C. John Carmack", "D. Doc Brown",
"A. Objective C", "B. B", "C. C++", "D. C#"};
char answers[] = {'B', 'A', 'B'};
int numberOfQuestions = sizeof(questions)/sizeof(questions[0]);
char guess;
int score;
printf("QUIZ GAME\n");
for(int i = 0; i < numberOfQuestions; i++)
{
printf("*********************\n");
printf("%s\n", questions[i]);
printf("*********************\n");
for(int j = (i * 4); j < (i * 4) + 4; j++)
{
printf("%s\n", options[j]);
}
printf("guess: ");
scanf("%c", &guess);
scanf("%c"); //clear \n from input buffer
guess = toupper(guess);
if(guess == answers[i])
{
printf("CORRECT!\n");
score++;
}
else
{
printf("WRONG!\n");
}
}
printf("*********************\n");
printf("FINAL SCORE: %d/%d\n", score, numberOfQuestions);
printf("*********************\n");
return 0;
}