-
Notifications
You must be signed in to change notification settings - Fork 0
/
QuizApp.cpp
251 lines (217 loc) · 9.01 KB
/
QuizApp.cpp
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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
#include <iostream>
#include "windows.h"
using namespace std;
/* Our structure should consist of 5 quiz questions. Each of the questions should have multiple (three) options for answers to be chosen from.
So, our structure has a text (question) parameter and an array of options (for the answers) parameter.
*/
struct QuizApp
{
string question;
string options[3]; // array of possible answers
};
int score; // a variable to keep track of the current score
int number_of_questions=5;
void display_1(QuizApp q1)
{
cout << "Question1: " << q1.question << endl;
cout << " 1. " << q1.options[0] << endl;
cout << " 2. " << q1.options[1] << endl;
cout << " 3. " << q1.options[2] << endl;
int user_answer_1;
cout << "Choose 1-3:" << " ";
cin >> user_answer_1;
while(user_answer_1 < 1 || user_answer_1 > 3){
cout << "Invalid! Please enter the option that's within the given range." << endl;
cout << "Choose 1-3:" << " ";
cin >> user_answer_1;
}
if(user_answer_1 != 3){
cout << "Incorrect! The correct answer is Burj Khalifa - Dubai. " << endl;
cout << "Current score: " << score << endl;
} else{
cout << "Hey, that's correct! Burj Khalifa (located in Dubai) is the tallest building in the world today with a height of around 830 meters from ground to the tip. " << endl;
score++;
cout << "Current score: " << score << endl;
}
}
void display_2(QuizApp q2)
{
cout << "Question2: " << q2.question << endl;
cout << " 1. " << q2.options[0] << endl;
cout << " 2. " << q2.options[1] << endl;
cout << " 3. " << q2.options[2] << endl;
int user_answer_2;
cout << "Choose 1-3:" << " ";
cin >> user_answer_2;
while(user_answer_2 < 1 || user_answer_2 > 3){
cout << "Invalid! Please enter the option that's within the given range." << endl;
cout << "Choose 1-3:" << " ";
cin >> user_answer_2;
}
if(user_answer_2 != 1){
cout << "Incorrect! The correct answer is Prairie. " << endl;
cout << "Current Score: " << score << endl;
} else{
cout << "Hey, that's correct! North American grasslands are indeed called prairies. " << endl;
score++;
cout << "Current score: " << score << endl;
}
}
void display_3(QuizApp q3)
{
cout << "Question3: " << q3.question << endl;
cout << " 1. " << q3.options[0] << endl;
cout << " 2. " << q3.options[1] << endl;
cout << " 3. " << q3.options[2] << endl;
int user_answer_3;
cout << "Choose 1-3:" << " ";
cin >> user_answer_3;
while(user_answer_3 < 1 || user_answer_3 > 3){
cout << "Invalid! Please enter the option that's within the given range." << endl;
cout << "Choose 1-3:" << " ";
cin >> user_answer_3;
}
if(user_answer_3 != 2){
cout << "Incorrect! The correct answer is Mariana Trench. " << endl;
cout << "Current score: " << score << endl;
} else{
cout << "Hey, that's correct! The Mariana Trench (located in the western Pacific Ocean) is the deepest oceanic trench in the world with a known depth of about 10,984 meters! " << endl;
score++;
cout << "Current score: " << score << endl;
}
}
void display_4(QuizApp q4)
{
cout << "Question4: " << q4.question << endl;
cout << " 1. " << q4.options[0] << endl;
cout << " 2. " << q4.options[1] << endl;
cout << " 3. " << q4.options[2] << endl;
int user_answer_4;
cout << "Choose 1-3:" << " ";
cin >> user_answer_4;
while(user_answer_4 < 1 || user_answer_4 > 3){
cout << "Invalid! Please enter the option that's within the given range." << endl;
cout << "Choose 1-3:" << " ";
cin >> user_answer_4;
}
if(user_answer_4 != 1){
cout << "Incorrect! The correct answer is Peru. " << endl;
cout << "Current score: " << score << endl;
} else{
cout << "Hey, that's correct! Machu-Pichu is a 15th century Inca (an ancient civilzation) citadel located in the Eastern Cordillera of southern Peru. " << endl;
score++;
cout << "Current score: " << score << endl;
}
}
void display_5(QuizApp q5)
{
cout << "Question5: " << q5.question << endl;
cout << " 1. " << q5.options[0] << endl;
cout << " 2. " << q5.options[1] << endl;
cout << " 3. " << q5.options[2] << endl;
int user_answer_5;
cout << "Choose 1-3:" << " ";
cin >> user_answer_5;
while(user_answer_5 < 1 || user_answer_5 > 3){
cout << "Invalid! Please enter the option that's within the given range." << endl;
cout << "Choose 1-3:" << " ";
cin >> user_answer_5;
}
if(user_answer_5 != 2){
cout << "Incorrect! The correct answer is Mars (Mt. Olympus Mons). " << endl;
cout << "Current score: " << score << endl;
} else{
cout << "Hey, that's correct! Mt. Olympus Mons is the tallest and widest/largest mountain (volcano) in the entire solar system with a height of over 21.9 kms. " << endl;
score++;
cout << "Current score: " << score << endl;
}
}
int main()
{
Sleep(1000);
//char user_name[50];
char first_name[20];
char last_name[20];
cout << endl;
cout << "==================== WELCOME TO FUN QUIZ! LET'S TEST YOUR GENERAL KNOWLEDGE ====================" << endl;
Sleep(1000);
cout << "\nWhat's your good name?: ";
cin >> first_name >> last_name;
Sleep(1000);
cout << "Hello " << first_name <<"! Buckle up." << endl;
cout << "This quiz is going to be interesting... \n";
Sleep(2000);
string reply;
cout << "Shall we begin then? Press Y to proceed N to terminate the quiz: ";
cin >> reply;
while (true){
if (reply == "Y" || reply == "y")
break;
else if(reply == "N" || reply == "n"){
cout << "Okay. You can try again sometime later...\n";
exit(0);
}
else{
cout << "Sorry, could you try again? Y - proceed N - terminate: ";
cin >> reply;
}
}
Sleep(1000);
cout << "Yay...good luck!" << endl;
Sleep(1000);
QuizApp Q_A_1;
string question_1 = "What is the tallest building in the world?";
string options_array_1[3] = {"Twin Towers - Kuala Lumpur", "Empire State Building - New York", "Burj Khalifa - Dubai"};
Q_A_1.question = question_1;
for (int i = 0; i < (sizeof(options_array_1)/sizeof(options_array_1[0])); i++)
Q_A_1.options[i] = options_array_1[i];
display_1(Q_A_1);
Sleep(2500); // The argument is in milliseconds.
QuizApp Q_A_2;
string question_2 = "What are the grasslands of North America called?";
string options_array_2[3] = {"Prairie", "Savannah", "Downs"};
Q_A_2.question = question_2;
for (int i=0; i < (sizeof(options_array_2)/sizeof(options_array_2[0])); i++)
Q_A_2.options[i] = options_array_2[i];
display_2(Q_A_2);
Sleep(2500);
QuizApp Q_A_3;
string question_3 = "What is the deepest oceanic trench in the world?";
string options_array_3[3] = {"Great Barrier Reef - Australia", "Mariana Trench - Pacific Ocean", "Tonga Trench - Pacific Ocean"};
Q_A_3.question = question_3;
for (int i=0; i < (sizeof(options_array_3)/sizeof(options_array_3[0])); i++)
Q_A_3.options[i] = options_array_3[i];
display_3(Q_A_3);
Sleep(2500);
QuizApp Q_A_4;
string question_4 = "Where is Machu-Pichu located?";
string options_array_4[3] = {"Peru", "Venezuela", "Chile"};
Q_A_4.question =question_4;
for (int i=0; i < (sizeof(options_array_4)/sizeof(options_array_4[0])); i++)
Q_A_4.options[i] = options_array_4[i];
display_4(Q_A_4);
Sleep(2500);
QuizApp Q_A_5;
string question_5 = "Where is the tallest mountain in our entire solar system located?";
string options_array_5[3] = {"Earth (Mt.Everest)", "Mars (Mt. Olympus Mons)", "Venus (Mt. Maxwell Montes)"};
Q_A_5.question = question_5;
for (int i=0; i < (sizeof(options_array_5)/sizeof(options_array_5[0])); i++)
Q_A_5.options[i] = options_array_5[i];
display_5(Q_A_5);
Sleep(2000);
if (score == number_of_questions){
cout << endl;
cout << "Hey, you answered all the questions correctly! You got a perfect score..." << endl;
Sleep(100);
cout << "GREAT JOB!" << endl;
}
else if(score == 0)
cout << "Hmm... You answered all the questions incorrectly. Not to worry; better luck next time!" << endl;
else{
cout << "You answered " << score << " question(s) correctly and " << number_of_questions-score << " question(s) incorrectly." << endl;
cout << "It's okay, learn from the incorrect ones and give it a try again!" << endl;
}
Sleep(1000);
cout << "\nThank you for taking Fun Quiz!\n" << endl;
return 0;
}