-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQuiz.c
492 lines (447 loc) · 13.9 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
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
//c project on quiz game
#include<stdio.h>
#include<conio.h>
#include<ctype.h>
#include<stdlib.h>
#include<string.h>
void show_record();
void reset_score();
void help();
void edit_score(float,char[]);
int main()
{
int countr,r,r1,count,i,n;
float score;
char choice;
char playername[20];
mainhome:
printf("\t\t\t << QUIZ GAME >>\n");
printf("\n\t\t****************************************");
printf("\n\t\t\t WELCOME\n ");
printf("\n\t\t\t to\n ");
printf("\n\t\t\t THE QUIZ GAME ");
printf("\n\t\t");
printf("\n\t\t****************************************");
printf("\n\t\t BECOME RICH EARN UPTO 1 MILLION $ ;-) ");
printf("\n\t\t****************************************");
printf("\n\t\t > Press S to start the game");
printf("\n\t\t > Press V to view the highest score ");
printf("\n\t\t > Press R to reset score");
printf("\n\t\t > press H for help ");
printf("\n\t\t > press Q to quit ");
printf("\n\t\t________________________________________\n\n");
choice=toupper(getch());
if(choice=='V')
{
system("cls");
show_record();
system("cls");
goto mainhome;
}
else if(choice=='H')
{
system("cls");
help();
getch();
system("cls");
goto mainhome;
}
else if(choice=='R')
{
system("cls");
reset_score();
getch();
goto mainhome;
}
else if (choice=='Q')
{
exit(1);
}
else if(choice=='S')
{
system("cls");
printf("\n\n\n\n\n\n\n\n\n\n\t\t\tResister your name:");
gets(playername);
system("cls");
printf("\n *********** Welcome %s to C Program Quiz Game *****************",playername);
printf("\n\n Here are some tips you might wanna know before playing:");
printf("\n ********************************************************************************");
printf("\n >> There are 2 rounds in this Quiz Game,WARMUP ROUND & CHALLANGE ROUND");
printf("\n >> In warmup round you will be asked a total of 3 questions to test your");
printf("\n general knowledge. You are eligible to play the game if you give atleast 2");
printf("\n right answers, otherwise you can't proceed further to the Challenge Round.");
printf("\n >> Your game starts with CHALLANGE ROUND. In this round you will be asked a");
printf("\n total of 10 questions. Each right answer will be awarded with 10 points!");
printf("\n By this way you can score upto 100 :-) :-):-):-):-):-):-)!!!!!..........");
printf("\n >> You will be given 4 options and you have to press A, B ,C or D for the");
printf("\n right option.");
printf("\n >> You will be asked questions continuously, till right answers are given");
printf("\n >> No negative marking for wrong answers!");
printf("\n\n\t!!!!!!!!!!!!! ALL THE BEST !!!!!!!!!!!!!");
printf("\n\n\n Press Y to start the game!\n");
printf("\n Press any other key to return to the main menu!");
if (toupper(getch())=='Y')
{
system("cls");
goto home;
}
else
{
system("cls");
goto mainhome;
}
home:
system("cls");
count=0;
for(i=1;i<=3;i++)
{
r1=i;
switch(r1)
{
case 1:
printf("\n\nA collecion of 8 bits are called?");
printf("\n\nA.bit\t\tB.word\n\nC.byte\t\tD.record");
if (toupper(getch())=='C')
{
printf("\n\nCorrect!!!");
count++;
getch();
system("cls");
break;
}
else
{
printf("\n\nWrong!!! The correct answer is C.byte");
getch();
system("cls");
break;
}
case 2:
printf("\n\nWhich of the following is a Palindrome number?");
printf("\n\nA.42042\t\tB.101010\n\nC.23232\t\tD.01234");
if (toupper(getch())=='C')
{
printf("\n\nCorrect!!!");
count++;
getch();
system("cls");
break;
}
else
{
printf("\n\nWrong!!! The correct answer is C.23232");
getch();
system("cls");
break;
}
system("cls");
case 3:
printf("\n\n\nWhich of the following is most oriented toward scientific programming ?");
printf("\n\nA.Cobol\t\tB.Fortran\n\nC.c++\t\tD.Basic");
if (toupper(getch())=='B')
{
printf("\n\nCorrect!!!");
count++;
getch();
system("cls");
break;
}
else
{
printf("\n\nWrong!!! The correct answer is B.Fortran");
getch();
system("cls");
break;
}
}
}
if(count>=2)
{
goto test;
}
else
{
system("cls");
printf("\n\nSORRY YOU ARE NOT ELIGIBLE TO PLAY THIS GAME, BETTER LUCK NEXT TIME");
getch();
goto mainhome;
}
test:
system("cls");
printf("\n\n\t*** CONGRATULATION %s you are eligible to play the Game ***",playername);
printf("\n\n\n\n\t!Press any key to Start the Game!");
if(toupper(getch())=='p')
{
goto game;
}
game:
countr=0;
for(i=1;i<=10;i++)
{
system("cls");
r=i;
switch(r)
{
case 1:
printf("\n\nAll are the example of input devices Except a:");
printf("\n\nA.Scanner\t\tB.Mouse\n\nC.Printer\t\tD.Keyboard");
if (toupper(getch())=='C')
{
printf("\n\nCorrect!!!");countr++;getch();
break;
getch();
}
else
{
printf("\n\nWrong!!! The correct answer is C.Printer");
getch();
goto score;
break;
}
case 2:
printf("\n\n\nWhat kind of file extension .mpg?,");
printf("\n\nA.Movie file \t\tB.Text file\n\nC.Image file\t\tD.Audio file");
if (toupper(getch())=='A')
{
printf("\n\nCorrect!!!");
countr++;
getch();
break;
}
else
{
printf("\n\nWrong!!! The correct answer is A.Movie file");
getch();
goto score;
break;
}
case 3:
printf("\n\n\nA DVD is an example of a/an.. ");
printf("\n\nA.Magnetic disk\t\tB.Hard disk\n\nC.Output device\t\tD.Optical disk");
if (toupper(getch())=='D')
{
printf("\n\nCorrect!!!");
countr++;
getch();
break;
}
else
{
printf("\n\nWrong!!! The correct answer is D.Optical disk");
getch();
goto score;
break;
}
case 4:
printf("\n\n\nWho is he founder of facebook?");
printf("\n\nA.Mark zuckerburg\tB.Tesla\n\nC.Steve jobs\t\tD.Bill gates");
if (toupper(getch())=='A')
{
printf("\n\nCorrect!!!");
countr++;
getch();
break;
}
else
{
printf("\n\nWrong!!! The correct answer is A.Mark zuckerburg");
getch();
goto score;
break;
}
case 5:
printf("\n\n\nWhich of he following is a web browser?");
printf("\n\nA.Dreamweaver\tB.Netscape navigator\n\nC.Maya\t\tD.Flash");
if(toupper(getch())=='B')
{
printf("\n\nCorrect!!!");
countr++;
getch();
break;}
else
{
printf("\n\nWrong!!! The correct answer is B.Netscape navigator");
getch();
goto score;
break;
}
case 6:
printf("\n\n\nWhat kind of file extension .bak?,");
printf("\n\nA.Backup file \t\tB.Text file\n\nC.Image file\t\tD.Audio file");
if (toupper(getch())=='A')
{
printf("\n\nCorrect!!!");
countr++;
getch();
break;}
else
{
printf("\n\nWrong!!! The correct answer is A.Backup file");
getch();
goto score;
break;
}
case 7:
printf("\n\n\nwhich of he following is a read only memory storage device ");
printf("\n\nA.Flash drive\t\tB.Hard disk\n\nC.Floppy disk\t\tD.CDROM");
if(toupper(getch())=='D')
{
printf("\n\nCorrect!!!");
countr++;
getch();
break;}
else
{
printf("\n\nWrong!!! The correct answer is D.CDROM");
getch();
goto score;
break;
}
case 8:
printf("\n\n\nThe _____ shows all the web sites any pages that you have visited one of recent time ");
printf("\n\nA.Hisory list\t\tB.Status bar \n\nC.task bar\t\tD.record");
if(toupper(getch())=='A')
{
printf("\n\nCorrect!!!");
countr++;
getch();
break;}
else
{
printf("\n\nWrong!!! The correct answer is A.Hisory list");
getch();
goto score;
break;
}
case 9:
printf("\n\n\nA 32 bit word computer can access ____ bytes at a time ");
printf("\n\nA.32\t\tB.16\n\nC.8\t\tD.4");
if(toupper(getch())=='C')
{
printf("\n\nCorrect!!!");
countr++;
getch();
break;}
else
{
printf("\n\nWrong!!! The correct answer is C.8");
getch();
goto score;
break;
}
case 10:
printf("\n\n\nWho is the founder of pixar animation?");
printf("\n\nA.Mark zuckerburg\tB.Tesla\n\nC.Steve jobs\t\tD.Bill gates");
if(toupper(getch())=='C')
{
printf("\n\nCorrect!!!");
countr++;
getch();
break;
}
else
{
printf("\n\nWrong!!! The correct answer is C.Steve jobs");
getch();
goto score;
break;
}
}
}
score:
system("cls");
score=(float)countr*100000;
if(score>0.00 && score<1000000)
{
printf("\n\n\t\t**************** CONGRATULATION *****************");
printf("\n\t You won $%.2f",score);
goto go;
}
else if(score==1000000.00)
{
printf("\n\n\n \t\t**************** CONGRATULATION ****************");
printf("\n\t\t\t\t YOU ARE A MILLIONAIRE!!!!!!!!!");
printf("\n\t\t\t\t You won $%.2f",score);
printf("\n\t\t\t\t Thank You !!");
}
else
{
printf("\n\n\t******** SORRY YOU DIDN'T WIN ANY CASH ********");
printf("\n\t\t Thanks for your participation");
printf("\n\t\t TRY AGAIN");
goto go;
}
go:
puts("\n\n Press Y if you want to play next game");
puts(" Press any key if you want to go main menu");
if (toupper(getchar())=='Y')
{
goto home;
}
else
{
edit_score(score,playername);
goto mainhome;
}
}
}
void show_record()
{
char name[20];
float scr=0;
FILE *f;
f=fopen("score.txt","r");
fscanf(f,"%s%f",&name,&scr);
printf("\n\n\t\t*************************************************************");
printf("\n\n\t\t %s has secured the Highest Score %f",name,scr);
printf("\n\n\t\t*************************************************************");
fclose(f);
getch();
}
void reset_score()
{
system("cls");
float sc;
char nm[20];
FILE *f;
f=fopen("score.txt","r+");
fscanf(f,"%s%f",&nm,&sc);
sc=0;
fprintf(f,"%s,%.2f",nm,sc);
fclose(f);
}
void help()
{
system("cls");
printf("\n\n HELP");
printf("\n -------------------------------------------------------------------------");
printf("\n ......................... C program Quiz Game...........");
printf("\n >> There are two rounds in the game, WARMUP ROUND & CHALLANGE ROUND");
printf("\n >> In warmup round you will be asked a total of 3 questions to test your general");
printf("\n knowledge. You will be eligible to play the game if you can give atleast 2");
printf("\n right answers otherwise you can't play the Game...........");
printf("\n >> Your game starts with the CHALLANGE ROUND. In this round you will be asked");
printf("\n total 10 questions each right answer will be awarded $100,000.");
printf("\n By this way you can win upto ONE MILLION cash prize in USD...............");
printf("\n >> You will be given 4 options and you have to press A, B ,C or D for the");
printf("\n right option");
printf("\n >> You will be asked questions continuously if you keep giving the right answers.");
printf("\n >> No negative marking for wrong answers");
printf("\n\n\t*********************BEST OF LUCK*********************************");
void edit_score(float score, char playernm[20])
{
system("cls");
float sc;
char nm[20];
FILE *f;
f=fopen("score.txt","r");
fscanf(f,"%s%f",&nm,&sc);
if (score>=sc)
{
sc=score;
fclose(f);
f=fopen("score.txt","w");
fprintf(f,"%s\n%.2f",playernm,sc); //print in player name
fclose(f);
}
}