├── README.md ├── .gitignore └── main.cpp /README.md: -------------------------------------------------------------------------------- 1 | # Basic-Quiz-Game-using-C 2 | The program uses basic input of question inside the program but You can upgrade to import from external file and implement randomization in this Game. 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Object files 5 | *.o 6 | *.ko 7 | *.obj 8 | *.elf 9 | 10 | # Linker output 11 | *.ilk 12 | *.map 13 | *.exp 14 | 15 | # Precompiled Headers 16 | *.gch 17 | *.pch 18 | 19 | # Libraries 20 | *.lib 21 | *.a 22 | *.la 23 | *.lo 24 | 25 | # Shared objects (inc. Windows DLLs) 26 | *.dll 27 | *.so 28 | *.so.* 29 | *.dylib 30 | 31 | # Executables 32 | *.exe 33 | *.out 34 | *.app 35 | *.i*86 36 | *.x86_64 37 | *.hex 38 | 39 | # Debug files 40 | *.dSYM/ 41 | *.su 42 | *.idb 43 | *.pdb 44 | 45 | # Kernel Module Compile Results 46 | *.mod* 47 | *.cmd 48 | .tmp_versions/ 49 | modules.order 50 | Module.symvers 51 | Mkfile.old 52 | dkms.conf 53 | -------------------------------------------------------------------------------- /main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | void show_record(); 7 | void reset_score(); 8 | void help(); 9 | void edit_score(float , char []); 10 | int main() 11 | { 12 | int countr,r,r1,count,i,n; 13 | float score; 14 | char choice; 15 | char playername[20]; 16 | mainhome: 17 | system("cls"); 18 | printf("\n\t\t________________________________________"); 19 | printf("\n\t\t\t WELCOME to Quiz Game"); 20 | printf("\n\t\t________________________________________"); 21 | printf("\n\t\t________________________________________"); 22 | printf("\n\t\t > Press S to start the game"); 23 | printf("\n\t\t > Press V to view the highest score "); 24 | printf("\n\t\t > Press R to reset score"); 25 | printf("\n\t\t > press H for help"); 26 | printf("\n\t\t > press Q to quit"); 27 | printf("\n\t\t________________________________________\n\n"); 28 | choice=toupper(getch()); 29 | if (choice=='V') 30 | { 31 | show_record(); 32 | goto mainhome; 33 | } 34 | else if (choice=='H') 35 | { 36 | help();getch(); 37 | goto mainhome; 38 | } 39 | else if (choice=='R') 40 | {reset_score(); 41 | getch(); 42 | goto mainhome;} 43 | else if (choice=='Q') 44 | exit(1); 45 | else if(choice=='S') 46 | { 47 | system("cls"); 48 | 49 | printf("\n\n\n\n\n\n\n\n\n\n\t\t\tResister your name:"); 50 | gets(playername); 51 | 52 | system("cls"); 53 | printf("\n ------------------ Welcome %s to Quiz Game --------------------------",playername); 54 | printf("\n\n Here are some tips you might wanna know before playing:"); 55 | printf("\n -------------------------------------------------------------------------"); 56 | printf("\n >> There are 2 rounds in this Quiz Game,WARMUP ROUND & CHALLANGE ROUND"); 57 | printf("\n >> In warmup round you will be asked a total of 3 questions to test your"); 58 | printf("\n general knowledge. You are eligible to play the game if you give atleast 2"); 59 | printf("\n right answers, otherwise you can't proceed further to the Challenge Round."); 60 | printf("\n >> Your game starts with CHALLANGE ROUND. In this round you will be asked a total of 10 questions."); 61 | printf("\n >> You will be given 4 options and you have to press A, B ,C or D for the right option."); 62 | printf("\n >> You will be asked questions continuously, till right answers are given"); 63 | printf("\n >> No negative marking for wrong answers!"); 64 | printf("\n\n\t!!!!!!!!!!!!! ALL THE BEST !!!!!!!!!!!!!"); 65 | printf("\n\n\n Press Y to start the game!\n"); 66 | printf("\n Press any other key to return to the main menu!"); 67 | if (toupper(getch())=='Y') 68 | { 69 | goto home; 70 | } 71 | else 72 | { 73 | goto mainhome; 74 | system("cls"); 75 | } 76 | 77 | home: 78 | system("cls"); 79 | count=0; 80 | for(i=1;i<=6;i++) 81 | { 82 | system("cls"); 83 | r1=i; 84 | 85 | 86 | switch(r1) 87 | { 88 | case 1: 89 | printf("\n\nWhich of the following is a Palindrome number?"); 90 | printf("\n\nA.42042\t\tB.101010\n\nC.23232\t\tD.01234"); 91 | if (toupper(getch())=='C') 92 | { 93 | printf("\n\nCorrect!!!");count++; 94 | getch(); 95 | break; 96 | } 97 | else 98 | { 99 | printf("\n\nWrong!!! The correct answer is C.23232"); 100 | getch(); 101 | break; 102 | } 103 | 104 | case 2: 105 | printf("\n\n\nThe country with the highest environmental performance index is..."); 106 | printf("\n\nA.France\t\tB.Denmark\n\nC.Switzerland\t\tD.Finland"); 107 | if (toupper(getch())=='C') 108 | {printf("\n\nCorrect!!!");count++; 109 | getch(); 110 | break;} 111 | else 112 | {printf("\n\nWrong!!! The correct answer is C.Switzerland"); 113 | getch(); 114 | break;} 115 | 116 | case 3: 117 | printf("\n\n\nWhich animal laughs like human being?"); 118 | printf("\n\nA.Polar Bear\t\tB.Hyena\n\nC.Donkey\t\tD.Chimpanzee"); 119 | if (toupper(getch())=='B') 120 | {printf("\n\nCorrect!!!");count++; 121 | getch(); 122 | break;} 123 | else 124 | {printf("\n\nWrong!!! The correct answer is B.Hyena"); 125 | getch(); 126 | break;} 127 | 128 | case 4: 129 | printf("\n\n\nWho was awarded the youngest player award in Fifa World Cup 2006?"); 130 | printf("\n\nA.Wayne Rooney\t\tB.Lucas Podolski\n\nC.Lionel Messi\t\tD.Christiano Ronaldo"); 131 | if (toupper(getch())=='B') 132 | {printf("\n\nCorrect!!!");count++; 133 | getch(); 134 | break;} 135 | else 136 | {printf("\n\nWrong!!! The correct answer is B.Lucas Podolski"); 137 | getch(); 138 | break;} 139 | 140 | case 5: 141 | printf("\n\n\nWhich is the third highest mountain in the world?"); 142 | printf("\n\nA.Mt. K2\t\tB.Mt. Kanchanjungha\n\nC.Mt. Makalu\t\tD.Mt. Kilimanjaro"); 143 | if (toupper(getch())=='B') 144 | {printf("\n\nCorrect!!!");count++; 145 | getch(); 146 | break;} 147 | else 148 | {printf("\n\nWrong!!! The correct answer is B.Mt. Kanchanjungha"); 149 | getch(); 150 | break;} 151 | 152 | case 6: 153 | printf("\n\n\nWhat is the group of frogs known as?"); 154 | printf("\n\nA.A traffic\t\tB.A toddler\n\nC.A police\t\tD.An Army"); 155 | if (toupper(getch())=='D' ) 156 | {printf("\n\nCorrect!!!");count++; 157 | getch(); 158 | break;} 159 | else 160 | {printf("\n\nWrong!!! The correct answer is D.An Army"); 161 | getch(); 162 | break;}} 163 | if(count>=2) 164 | { 165 | break; 166 | } 167 | } 168 | 169 | if(count>=2) 170 | {goto test;} 171 | else 172 | { 173 | system("cls"); 174 | printf("\n\nSORRY YOU ARE NOT ELIGIBLE TO PLAY THIS GAME, BETTER LUCK NEXT TIME"); 175 | getch(); 176 | goto mainhome; 177 | } 178 | test: 179 | system("cls"); 180 | printf("\n\n\t*** CONGRATULATION %s you are eligible to play the Game ***",playername); 181 | printf("\n\n\n\n\t!Press any key to Start the Game!"); 182 | if(toupper(getch())=='p') 183 | {goto game;} 184 | game: 185 | countr=0; 186 | for(i=1;i<=10;i++) 187 | {system("cls"); 188 | r=i; 189 | 190 | switch(r) 191 | { 192 | case 1: 193 | printf("\n\nWhat is the National Game of England?"); 194 | printf("\n\nA.Football\t\tB.Basketball\n\nC.Cricket\t\tD.Baseball"); 195 | if (toupper(getch())=='C') 196 | {printf("\n\nCorrect!!!");countr++;getch(); 197 | break;getch();} 198 | else 199 | {printf("\n\nWrong!!! The correct answer is C.Cricket");getch(); 200 | goto score; 201 | break;} 202 | 203 | case 2: 204 | printf("\n\n\nStudy of Earthquake is called............,"); 205 | printf("\n\nA.Seismology\t\tB.Cosmology\n\nC.Orology\t\tD.Etimology"); 206 | if (toupper(getch())=='A') 207 | {printf("\n\nCorrect!!!");countr++;getch(); 208 | break;} 209 | else 210 | {printf("\n\nWrong!!! The correct answer is A.Seismology");getch(); 211 | goto score; 212 | break; 213 | } 214 | 215 | case 3: 216 | printf("\n\n\nAmong the top 10 highest peaks in the world, how many lie in Nepal? "); 217 | printf("\n\nA.6\t\tB.7\n\nC.8\t\tD.9"); 218 | if (toupper(getch())=='C') 219 | {printf("\n\nCorrect!!!");countr++;getch(); 220 | break;} 221 | else 222 | {printf("\n\nWrong!!! The correct answer is C.8");getch(); 223 | goto score; 224 | break;} 225 | 226 | case 4: 227 | printf("\n\n\nThe Laws of Electromagnetic Induction were given by?"); 228 | printf("\n\nA.Faraday\t\tB.Tesla\n\nC.Maxwell\t\tD.Coulomb"); 229 | if (toupper(getch())=='A') 230 | {printf("\n\nCorrect!!!");countr++;getch(); 231 | break;} 232 | else 233 | { 234 | printf("\n\nWrong!!! The correct answer is A.Faraday");getch(); 235 | goto score; 236 | break; 237 | } 238 | 239 | case 5: 240 | printf("\n\n\nIn what unit is electric power measured?"); 241 | printf("\n\nA.Coulomb\t\tB.Watt\n\nC.Power\t\tD.Units"); 242 | if (toupper(getch())=='B') 243 | {printf("\n\nCorrect!!!");countr++;getch(); break;} 244 | else 245 | { 246 | printf("\n\nWrong!!! The correct answer is B.Power"); 247 | getch(); 248 | goto score; 249 | break; 250 | } 251 | 252 | case 6: 253 | printf("\n\n\nWhich element is found in Vitamin B12?"); 254 | printf("\n\nA.Zinc\t\tB.Cobalt\n\nC.Calcium\t\tD.Iron"); 255 | if (toupper(getch())=='B' ) 256 | {printf("\n\nCorrect!!!");countr++;getch(); 257 | break;} 258 | else 259 | {printf("\n\nWrong!!! The correct answer is B.Cobalt");goto score; 260 | getch(); 261 | break;} 262 | 263 | case 7: 264 | printf("\n\n\nWhat is the National Name of Japan?"); 265 | printf("\n\nA.Polska\t\tB.Hellas\n\nC.Drukyul\t\tD.Nippon"); 266 | if (toupper(getch())=='D') 267 | {printf("\n\nCorrect!!!");countr++;getch(); 268 | break;} 269 | else 270 | {printf("\n\nWrong!!! The correct answer is D.Nippon");getch(); 271 | goto score; 272 | break;} 273 | 274 | case 8: 275 | printf("\n\n\nHow many times a piece of paper can be folded at the most?"); 276 | printf("\n\nA.6\t\tB.7\n\nC.8\t\tD.Depends on the size of paper"); 277 | if (toupper(getch())=='B') 278 | {printf("\n\nCorrect!!!");countr++;getch(); break;} 279 | else 280 | {printf("\n\nWrong!!! The correct answer is B.7");getch(); 281 | goto score; 282 | break;} 283 | 284 | case 9: 285 | printf("\n\n\nWhat is the capital of Denmark?"); 286 | printf("\n\nA.Copenhagen\t\tB.Helsinki\n\nC.Ajax\t\tD.Galatasaray"); 287 | if (toupper(getch())=='A') 288 | {printf("\n\nCorrect!!!");countr++; getch(); 289 | break;} 290 | else 291 | {printf("\n\nWrong!!! The correct answer is A.Copenhagen");getch(); 292 | goto score; 293 | break;} 294 | 295 | case 10: 296 | printf("\n\n\nWhich is the longest River in the world?"); 297 | printf("\n\nA.Nile\t\tB.Koshi\n\nC.Ganga\t\tD.Amazon"); 298 | if (toupper(getch())=='A') 299 | {printf("\n\nCorrect!!!");countr++;getch(); break;} 300 | else 301 | {printf("\n\nWrong!!! The correct answer is A.Nile");getch();break;goto score;} 302 | 303 | case 11: 304 | printf("\n\n\nWhat is the color of the Black Box in aeroplanes?"); 305 | printf("\n\nA.White\t\tB.Black\n\nC.Orange\t\tD.Red"); 306 | if (toupper(getch())=='C') 307 | {printf("\n\nCorrect!!!");countr++;getch(); 308 | break;} 309 | else 310 | {printf("\n\nWrong!!! The correct answer is C.Orange");getch(); 311 | break;goto score;} 312 | 313 | case 12: 314 | printf("\n\n\nWhich city is known at 'The City of Seven Hills'?"); 315 | printf("\n\nA.Rome\t\tB.Vactican City\n\nC.Madrid\t\tD.Berlin"); 316 | if (toupper(getch())=='A') 317 | {printf("\n\nCorrect!!!");countr++;getch(); 318 | break;} 319 | else 320 | {printf("\n\nWrong!!! The correct answer is A.Rome");getch(); 321 | break;goto score;} 322 | 323 | case 13: 324 | printf("\n\n\nName the country where there no mosquitoes are found?"); 325 | printf("\n\nA.Japan\t\tB.Italy\n\nC.Argentina\t\tD.France"); 326 | if (toupper(getch())=='D') 327 | {printf("\n\nCorrect!!!");countr++;getch(); 328 | break;} 329 | else 330 | {printf("\n\nWrong!!! The correct answer is D.France");getch(); 331 | break;goto score;} 332 | 333 | case 14: 334 | printf("\n\n\nWho is the author of 'Pulpasa Cafe'?"); 335 | printf("\n\nA.Narayan Wagle\t\tB.Lal Gopal Subedi\n\nC.B.P. Koirala\t\tD.Khagendra Sangraula"); 336 | if (toupper(getch())=='A') 337 | {printf("\n\nCorrect!!!");countr++;getch(); 338 | break;} 339 | else 340 | {printf("\n\nWrong!!! The correct answer is A.Narayan Wagle");getch(); 341 | break;goto score;} 342 | 343 | case 15: 344 | printf("\n\n\nWhich Blood Group is known as the Universal Recipient?"); 345 | printf("\n\nA.A\t\tB.AB\n\nC.B\t\tD.O"); 346 | if (toupper(getch())=='B') 347 | {printf("\n\nCorrect!!!");countr++;getch(); 348 | break;} 349 | else 350 | {printf("\n\nWrong!!! The correct answer is B.AB");getch(); 351 | goto score; 352 | break;} 353 | 354 | case 16: 355 | printf("\n\n\nWhat is the unit of measurement of distance between Stars?"); 356 | printf("\n\nA.Light Year\t\tB.Coulomb\n\nC.Nautical Mile\t\tD.Kilometer"); 357 | if (toupper(getch())=='A') 358 | {printf("\n\nCorrect!!!");countr++; getch(); 359 | break; 360 | } 361 | else 362 | {printf("\n\nWrong!!! The correct answer is A.Light Year");getch(); 363 | goto score; 364 | break;} 365 | 366 | 367 | case 17: 368 | printf("\n\n\nThe country famous for Samba Dance is........"); 369 | printf("\n\nA.Brazil\t\tB.Venezuela\n\nC.Nigeria\t\tD.Bolivia"); 370 | if (toupper(getch())=='A') 371 | {printf("\n\nCorrect!!!");countr++; getch(); 372 | break;} 373 | else 374 | {printf("\n\nWrong!!! The correct answer is A.Brazil");getch();goto score; 375 | break;} 376 | 377 | case 18: 378 | printf("\n\n\nWind speed is measure by__________?"); 379 | printf("\n\nA.Lysimeter\t\tB.Air vane\n\nC.Hydrometer\t\tD.Anemometer\n\n"); 380 | if (toupper(getch())=='D') 381 | {printf("\n\nCorrect!!!");countr++; getch(); 382 | break;} 383 | else 384 | {printf("\n\nWrong!!! The correct answer is D.Anemometer");getch();goto score; 385 | break;} 386 | 387 | case 19: 388 | printf("\n\n\nWhich city in the world is popularly known as The City of Temple?"); 389 | printf("\n\nA.Delhi\tB.Bhaktapur\n\nC.Kathmandu\tD.Agra\n\n"); 390 | if (toupper(getch())=='C') 391 | {printf("\n\nCorrect!!!");countr++; getch(); 392 | break;} 393 | else 394 | {printf("\n\nWrong!!! The correct answer is C.Kathmandu");getch();goto score; 395 | break;} 396 | 397 | case 20: 398 | printf("\n\n\nWhich hardware was used in the First Generation Computer?"); 399 | printf("\n\nA.Transistor\t\tB.Valves\n\nC.I.C\t\tD.S.S.I"); 400 | if (toupper(getch())=='B') 401 | {printf("\n\nCorrect!!!");countr++; getch(); 402 | break;} 403 | else 404 | {printf("\n\nWrong!!! The correct answer is B.Valves");getch();goto score; 405 | break;} 406 | 407 | case 21: 408 | printf("\n\n\nOzone plate is being destroyed regularly because of____ ?"); 409 | printf("\n\nA.L.P.G\t\tB.Nitrogen\n\nC.Methane\t\tD. C.F.C"); 410 | if (toupper(getch())=='D') 411 | {printf("\n\nCorrect!!!");countr++; getch(); 412 | break;} 413 | else 414 | {printf("\n\nWrong!!! The correct answer is D. C.F.C");getch();goto score; 415 | break;} 416 | 417 | case 22: 418 | printf("\n\n\nWho won the Women's Australian Open Tennis in 2007?"); 419 | printf("\n\nA.Martina Hingis\t\tB.Maria Sarapova\n\nC.Kim Clijster\t\tD.Serena Williams"); 420 | if (toupper(getch())=='D') 421 | {printf("\n\nCorrect!!!");countr++; getch(); 422 | break;} 423 | else 424 | {printf("\n\nWrong!!! The correct answer is D.Serena Williams");getch();goto score; 425 | break;} 426 | 427 | case 23: 428 | printf("\n\n\nWhich film was awarded the Best Motion Picture at Oscar in 2010?"); 429 | printf("\n\nA.The Secret in their Eyes\t\tB.Shutter Island\n\nC.The King's Speech\t\tD.The Reader"); 430 | if (toupper(getch())=='C') 431 | {printf("\n\nCorrect!!!");countr++; getch(); 432 | break;} 433 | else 434 | {printf("\n\nWrong!!! The correct answer is C.The King's Speech");getch();goto score; 435 | break;}}} 436 | score: 437 | system("cls"); 438 | score=countr*1; 439 | if(score>0) 440 | { 441 | printf("\n\n\t\t**************** CONGRATULATION *****************"); 442 | printf("Your score is %d",score); 443 | goto go; 444 | } 445 | else 446 | { 447 | printf("\n\n\t******** SORRY FOR YOUR LOSS ********"); 448 | printf("\n\t\t Thanks for your participation"); 449 | printf("\n\t\t TRY AGAIN"); 450 | goto go; 451 | } 452 | 453 | go: 454 | puts("\n\n Press Y if you want to play next game"); 455 | puts(" Press any key if you want to go main menu"); 456 | if (toupper(getch())=='Y') 457 | goto home; 458 | else 459 | { 460 | edit_score(score,playername); 461 | goto mainhome;}}} 462 | 463 | void show_record() 464 | { 465 | system("cls"); 466 | char name[20]; 467 | int scr; 468 | FILE*f; 469 | f=fopen("score.txt","r"); 470 | fscanf(f,"%s%d",&name,&scr); 471 | printf("\n\n\t\t*************************************************************"); 472 | printf("\n\n\t\t %s has secured the Highest Score %d",name,scr); 473 | printf("\n\n\t\t*************************************************************"); 474 | fclose(f); 475 | getch();} 476 | 477 | void reset_score() 478 | {system("cls"); 479 | int sc; 480 | char nm[20]; 481 | FILE *f; 482 | f=fopen("score.txt","r+"); 483 | fscanf(f,"%s%d",&nm,&sc); 484 | sc=0; 485 | fprintf(f,"%s,%d",nm,sc); 486 | fclose(f);} 487 | 488 | void help() 489 | {system("cls"); 490 | printf("\n\n HELP"); 491 | printf("\n -------------------------------------------------------------------------"); 492 | printf("\n ......................... C program Quiz Game..........."); 493 | printf("\n >> There are two rounds in the game, WARMUP ROUND & CHALLANGE ROUND"); 494 | printf("\n >> In warmup round you will be asked a total of 3 questions to test your general"); 495 | printf("\n knowledge. You will be eligible to play the game if you can give atleast 2"); 496 | printf("\n right answers otherwise you can't play the Game..........."); 497 | printf("\n >> Your game starts with the CHALLANGE ROUND. In this round you will be asked"); 498 | printf("\n total 10 questions each right answer will be awarded 1 Point."); 499 | printf("\n >> You will be given 4 options and you have to press A, B ,C or D for the right option"); 500 | printf("\n >> You will be asked questions continuously if you keep giving the right answers."); 501 | printf("\n >> No negative marking for wrong answers"); 502 | 503 | printf("\n\n\t*********************BEST OF LUCK*********************************"); 504 | } 505 | void edit_score(float score, char plnm[20]) 506 | {system("cls"); 507 | int sc; 508 | char nm[20]; 509 | FILE *f; 510 | f=fopen("score.txt","r"); 511 | fscanf(f,"%s%d",&nm,&sc); 512 | if (score>=sc) 513 | { sc=score; 514 | fclose(f); 515 | f=fopen("score.txt","w"); 516 | fprintf(f,"%s\n%d",plnm,sc); 517 | fclose(f);}} 518 | --------------------------------------------------------------------------------