forked from malmhaug/C_AbsBegin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathC5E4TriviaTrackedAnswere.c
209 lines (157 loc) · 6.72 KB
/
C5E4TriviaTrackedAnswere.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
/* Challanges Ch5E4 - TriviaTrackedAnswer */
// By Jim-Kristian Malmhaug | Date: 10 September 2013
//Notes: The original Trivia with two extra categories and tracking of correct/incorrect answers.
//References:
#include <stdio.h>
/*****************************************************
FUNCTION PROTOTYPES
*****************************************************/
int sportsQuestion(void);
int geographyQuestion(void);
int astronomyQuestion(void);
int mathQuestion(void);
void pause(int);
/****************************************************/
/*****************************************************
GLOBAL VARIABLE
*****************************************************/
int giResponse = 0;
int giCorrectAnsw = 0;
int giIncorrectAnsw = 0;
int giNumQuestions = 0;
/****************************************************/
main() {
do {
system("clear");
printf("\n\tTHE TRIVIA GAME\n\n");
printf("1\tSports\n");
printf("2\tGeography\n");
printf("3\tAstronomy\n");
printf("4\tMath\n");
printf("5\tQuit\n");
printf("\n\nEnter your selection: ");
scanf("%d", &giResponse);
switch(giResponse) {
case 1:
if(sportsQuestion() == 4) {
printf("\nCorrect!\n");
giCorrectAnsw++;
} else {
printf("\nIncorrect\n");
giIncorrectAnsw++;
}
giNumQuestions++;
pause(2);
break;
case 2:
if(geographyQuestion() == 2) {
printf("\nCorrect!\n");
giCorrectAnsw++;
} else {
printf("\nIncorrect!\n");
giIncorrectAnsw++;
}
giNumQuestions++;
pause(2);
break;
case 3:
if(astronomyQuestion() == 3) {
printf("\nCorrect!\n");
giCorrectAnsw++;
} else {
printf("\nIncorrect!\n");
giIncorrectAnsw++;
}
giNumQuestions++;
pause(2);
break;
case 4:
if(mathQuestion() == 4) {
printf("\nCorrect!\n");
giCorrectAnsw++;
} else {
printf("\nIncorrect!\n");
giIncorrectAnsw++;
}
giNumQuestions++;
pause(2);
break;
} //end switch
} while(giResponse != 5);
printf("\n\nYou answered %d correct questions and %d incorrect questions out of %d questions.\n\n", giCorrectAnsw, giIncorrectAnsw, giNumQuestions);
} //end main function
/*********************************************************************************
FUNCTION DEFINITION
*********************************************************************************/
int sportsQuestion(void) {
int iAnswer = 0;
system("clear");
printf("\tSports Question\n");
printf("\nWhat University did NFL star Deon Sanders attend? ");
printf("\n\n1\tUniversity of Miami\n");
printf("2\tCalifornia State University\n");
printf("3\tIndiana University\n");
printf("4\tFlorida State University\n");
printf("\nEnter your selection: ");
scanf("%d", &iAnswer);
return iAnswer;
} //end SportsQuestion function
/*********************************************************************************
FUNCTION DEFINITION
*********************************************************************************/
int geographyQuestion(void) {
int iAnswer = 0;
system("clear");
printf("\tGeography Question\n");
printf("\nWhat is the state capitol of Florida? ");
printf("\n\n1\tPenescola\n");
printf("2\tTallahassee\n");
printf("3\tJacksonville\n");
printf("4\tMiami\n");
printf("\nEnter your selection: ");
scanf("%d", &iAnswer);
return iAnswer;
} //end geographyQuestion function
/*********************************************************************************
FUNCTION DEFINITION
*********************************************************************************/
int astronomyQuestion(void) {
int iAnswer = 0;
system("clear");
printf("\tAstronomy Question\n");
printf("\nWhat is the other name for Earth? ");
printf("\n\n1\tQuphar\n");
printf("2\tTargus\n");
printf("3\tTellus\n");
printf("4\tTrellus\n");
printf("\nEnter your selection: ");
scanf("%d", &iAnswer);
return iAnswer;
}
/*********************************************************************************
FUNCTION DEFINITION
*********************************************************************************/
int mathQuestion(void) {
int iAnswer = 0;
system("clear");
printf("\tMath Question\n");
printf("\nWhat is Newtons first name? ");
printf("\n\n1\tFrodo\n");
printf("2\tCristopher\n");
printf("3\tCollin\n");
printf("4\tIsaac\n");
printf("\nEnter your selection: ");
scanf("%d", &iAnswer);
return iAnswer;
}
/*********************************************************************************
FUNCTION DEFINITION
*********************************************************************************/
void pause(int inNum) {
int iCurrentTime = 0;
int iElapsedTime = 0;
iCurrentTime = time(NULL);
do {
iElapsedTime = time(NULL);
} while ((iElapsedTime - iCurrentTime) < inNum);
} //end pause function