-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQuiz.c
474 lines (435 loc) · 14.7 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
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
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
# Quiz_C
#include<stdio.h>
//declaration and initialization
int correct_answer=0;
int wrong_answer=0;
double percentage;
char name [50];
int choice;
struct student
{
char name [50];
int age;
char email [100];
int contact;
}s;
//main function
int main()
{
printf(" *****QUIZ***** \n");
printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ \n");
printf("\n");
printf(" Before starting please do read the following instructions: \n");
printf("* There will be three topics for this quiz, you will have to choose one of them. \n");
printf("* There would be a total of 5 questions. \n");
printf("* For each questions you would have four possible answers. \n");
printf("* Enter the answer which you think would be right that is either a,b,c or d \n");
printf("* Do not enter two options, it will be considerd wrong. \n");
printf("* At the end of this quiz, your results will be displayed. \n");
printf("* Your results would show your right answers, wrong answers and your overall percentage. \n");
printf("\n");
printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ \n");
printf("\n");
printf("To start this quiz enter the following details: \n");
printf("\n");
//registration
printf("Enter your name : \n");
scanf("%s", s.name);
printf("\n");
printf("Enter your age : \n");
scanf("%d", &s.age);
printf("\n");
printf("Enter your email ID : \n");
scanf("%s", s.email);
printf("\n");
printf("Enter your contact number : \n");
scanf("%d", &s.contact);
printf("\n");
printf("\n");
printf("\n");
//displaying the topics for the quiz
printf("**The topics for this quiz are** \n");
printf("1. All about Computers \n");
printf("2. Math fun \n");
printf("****** \n");
printf("Enter your choice: \n");
scanf("%d", &choice);
printf("\n");
//starting swith
switch(choice)
{
case 1:
comp();
results();
screen();
certificate();
break;
case 2:
math();
results();
screen();
certificate();
break;
default:
printf("Invalid input \n");
}
}
//function to display topic 1
void comp()
{
//correct options
char b[10];
b[0]="c";
b[1]="a";
b[2]="d";
b[3]="b";
b[4]="a";
b[5]="c";
b[6]="b";
b[7]="b";
b[8]="d";
b[9]="c";
printf("Your choice is : 1. All about Computers \n");
printf("Lets start the game! \n");
printf("\n");
printf("\n");
//declare an array
char a[10];
//display the question and options for topic 1
printf("1.How to run Java program on the command prompt? \n");
printf("a.javac JavaProgram \n");
printf("b.javac JavaProgram.java \n");
printf("c.java JavaProgram \n");
printf("d.No one \n");
printf("Your option is: ");
scanf("%c", &a[0]);
printf("\n");
if (a[0]==b[0])
{
printf("Bravo! your answer is right :-) \n");
printf("You're going on the right track!! \n");
correct_answer++;
printf("\n");
}
else
{
printf("Sorry your answer is wrong :-( \n");
printf("The right answer is: c.java JavaProgram. \n");
printf("Try your luck in the next question... \n");
wrong_answer++;
printf("\n");
}
printf("2.What is the use of the println method? \n");
printf("a.It is used to print text on the screen with the line break. \n");
printf( "b.It is used to print text on the screen. \n");
printf("c.It is used to read text from keyboard. \n");
printf("d.It is used to read text from a file. \n");
printf("Your option is: ");
scanf("%c", &a[1]);
printf("\n");
if (a[1]==b[1])
{
printf("Bravo! your answer is right :-) \n");
printf("You're going on the right track!! \n");
correct_answer++;
printf("\n");
}
else
{
printf("Sorry your answer is wrong :-( \n");
printf("The right answer is:a.It is used to print text on the screen with the line break.\n");
printf("Try your luck in the next question... \n");
wrong_answer++;
printf("\n");
}
printf("3.How to read a character from the keyboard? \n");
printf("a.char c=System.read() \n");
printf("b.char c=System.in.read() \n");
printf("c.char c=(char)System.read() \n");
printf("d.char c=(char)System.in.read() \n");
printf("Your option is: ");
scanf("%c", &a[2]);
printf("\n");
if (a[2]==b[2])
{
printf("Bravo! your answer is right :-) \n");
printf("You're going on the right track!! \n");
correct_answer++;
printf("\n");
}
else
{
printf("Sorry your answer is wrong :-( \n");
printf("The right answer is:d.char c=(char)System.in.read() \n");
printf("Try your luck in the next question... \n");
wrong_answer++;
printf("\n");
}
printf("4.Which one is a single-line comment? \n");
printf("a./... \n");
printf("b.//... \n");
printf("c./*... \n");
printf("d./*...*/ \n");
printf("Your option is: ");
scanf("%c", &a[3]);
printf("\n");
if (a[3]==b[3])
{
printf("Bravo! your answer is right :-) \n");
printf("You're going on the right track!! \n");
correct_answer++;
printf("\n");
}
else
{
printf("Sorry your answer is wrong :-( \n");
printf("The right answer is:b.//... \n");
printf("Try your luck in the next question... \n");
wrong_answer++;
printf(",\n");
}
printf("5.How do you declare an integer variable x? \n");
printf("a.int x \n");
printf("b.x as Integer \n");
printf("c.Int[] x \n");
printf("d.No one is correct. \n");
printf("Your option is: ");
scanf("%c", &a[4]);
printf("\n");
if (a[4]==b[4])
{
printf("Bravo! your answer is right :-) \n");
printf("You're going on the right track!! \n");
correct_answer++;
printf("\n");
}
else
{
printf("Sorry your answer is wrong :-( \n");
printf("The right answer is:a.int x \n");
printf("Try your luck in the next question... \n");
wrong_answer++;
printf("\n");
}
//find the average percentage of the candidate
percentage = correct_answer*10;
}
//function to display topic 2
void math()
{
//correct options
char d[10];
d[0]="b";
d[1]="a";
d[2]="c";
d[3]="b";
d[4]="c";
d[5]="b";
d[6]="b";
d[7]="a";
d[8]="d";
d[9]="d";
printf("Your choice is : 2. Math \n");
printf("Lets start the game! \n");
printf("\n");
//declare an array
char c[10];
//display the question and options for topic 2
printf("1.The average of first 50 natural numbers. \n");
printf("a.25.30 \n");
printf("b.25.5 \n");
printf("c.25.00 \n");
printf("d.12.25 \n");
printf("Your option is: ");
scanf("%c", &c[0]);
printf("\n");
if (c[0]==d[0])
{
printf("Bravo! your answer is right :-) \n");
printf("You're going on the right track!! \n");
correct_answer++;
printf("\n");
}
else
{
printf("Sorry your answer is wrong :-( \n");
printf("The right answer is:b.25.5 \n");
printf("Try your luck in the next question... \n");
wrong_answer++;
printf("\n");
}
printf("2.A fraction which bears the same ratio to 1/27 as 3/11 bear to 5/9 is equal to? \n");
printf("a.1/55 \n");
printf("b.55 \n");
printf("c.3/11 \n");
printf("d.1/11 \n");
printf("Your option is: ");
scanf("%c", &c[1]);
printf("\n");
if (c[1]==d[1])
{
printf("Bravo! your answer is right :-) \n");
printf("You're going on the right track!!\n");
correct_answer++;
printf("\n");
}
else
{
printf("Sorry your anwser is wrong :-( \n");
printf("The right answer is:a.1/55 \n");
printf("Try your luck in the next question... \n");
wrong_answer++;
printf("\n");
}
printf("3.The number of 3-digit numbers divisible by 6 \n");
printf("a.149 \n");
printf("b.166 \n");
printf("c.150 \n");
printf("d.151 \n");
printf("Your option is: ");
scanf("%c", &c[2]);
printf("\n");
if (c[2]==d[2])
{
printf("Bravo! your answer is right :-) \n");
printf("You're going on the right track!! \n");
correct_answer++;
printf("\n");
}
else
{
printf("Sorry your answer is wrong :-( \n");
printf("The right answer is:c.150 \n");
printf("Try your luck in the next question... \n");
wrong_answer++;
printf("\n");
}
printf("4.What is 1004 divided by 2? \n");
printf("a.52 \n");
printf("b.502 \n");
printf("c.520 \n");
printf("d.5002 \n");
printf("Your option is: ");
scanf("%c", &c[3]);
printf("\n");
if (c[3]==d[3])
{
printf("Bravo! your answer is right :-) \n");
printf("You're going on the right track!! \n");
correct_answer++;
printf("\n");
}
else
{
printf("Sorry your answer is wrong :-( \n");
printf("The right answer is:b.502 \n");
printf("Try your luck in the next question... \n");
wrong_answer++;
printf("\n");
}
printf("5.A clock strikes once at 1 o’clock, twice at 2 o’clock, thrice at 3 o’clock and so on. How many times will it strike in 24 hours? \n");
printf("a.78 \n");
printf("b.136 \n");
printf("c.156 \n");
printf("d.196 \n");
printf("Your option is: ");
scanf("%c", &c[4]);
printf("\n");
if (c[4]==d[4])
{
printf("Bravo! your answer is right :-) \n");
printf("You're going on the right track!! \n");
correct_answer++;
printf("\n");
}
else
{
printf("Sorry your answer is wrong :-( \n");
printf("The right answer is:c.156 \n");
printf("Try your luck in the next question...\n");
wrong_answer++;
printf("\n");
}
//find the average percentage of the candidate
percentage = correct_answer*10;
}
//function display the results
void results()
{
printf("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n");
printf("\n");
printf("\n");
printf(" YOUR RESULTS \n");
printf("\n");
printf("The number of correct answers is ",correct_answer,"/10 \n");
printf("The number of wrong answers is ",wrong_answer,"/10 \n");
printf("Your average percentage is ",percentage,"% \n");
printf("\n");
printf("\n");
printf("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n");
}
//function to create an illusion
void screen()
{
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("\n");
printf("\n");
}
//function to display the certificate
void certificate()
{
if(percentage>=80)
{
if(choice==1)
{
printf(" CERTIFICATE OF DISTINCTION \n");
printf("This is to certify that ",name," has completed the online quiz on topic 1 'All About Computers' with ",percentage,"% \n");
}
else if(choice==2)
{
printf(" CERTIFICATE OF DISTINCTION \n");
printf("This is to certify that ",name," has completed the online quiz on topic 2 'Math' with ",percentage,"% \n");
}
}
else if(percentage<80 && percentage>=50)
{
if(choice==1)
{
printf(" CERTIFICATE OF MERIT \n");
printf("This is to certify that ",name," has completed the online quiz on topic 1 'All About Computers' with ",percentage,"% \n");
}
else if(choice==2)
{
printf(" CERTIFICATE OF MERIT \n");
printf("This is to certify that ",name," has completed the online quiz on topic 2 'Math' with ",percentage,"% \n");
}
}
else
{
if(choice==1)
{
printf(" CERTIFICATE FOR PARTICIPATION \n");
printf("This is to certify that ",name," has completed the online quiz on topic 1 'All About Computers' with ",percentage,"% \n");
}
else if(choice==2)
{
printf(" CERTIFICATE FOR PARTICIPATION \n");
printf("This is to certify that ",name," has completed the online quiz on topic 2 'Math' with ",percentage,"% \n");
}
}
}