C Programming Mini Project On Puzzle Game

 Puzzle 
Programming

#include<stdio.h> (#include is the inclusion of stdio, stdio.h is known to contain the input and output operations like "printf" or "scanf" & "h" extension means the header file)

#include<conio.h> (# include is a preprocessor directive  used to paste the code of given file to the current file and conio.h is a non standard header file)

#include<ctype.h> (ctype.h is the header file which declares several functions that are useful for testing and mapping characters)

#include<stdlib.h> (stdlib.h is the header file which defines four variable types i.e. size_t, wchar_t, div_t & Idiv_t, several macros & various functions for performing general functions)

#include<string.h> (h is the header file required for string functions. This function appends not more than n characters from the string pointed to by src to the end of the string pointed to by dest plus a terminating Null-character)

void show_record(); (void function)

void reset_score(); (void function)

void help(); (void function)

void edit_score(float , char []); (void function in bracket parameters declared)

int main() (main function starts)

{ (Brace open)

int countr,r,r1,count,i,n; (variables declared)
     
float score; (variable declared)

char choice; (variable declared)

 char playername[20]; (variable declared & in bracket value given of the variable playername)
     
mainhome: 

system("cls"); 

printf("\t\t\tC PROGRAM QUIZ GAME\n"); (print statement)

printf("\n\t\t________________________________________"); (print statement)

printf("\n\t\t\t   WELCOME "); (print statement)

printf("\n\t\t\t      to "); (print statement)

printf("\n\t\t\t   THE GAME "); (print statement)

printf("\n\t\t________________________________________"); (print statement)

printf("\n\t\t________________________________________"); (print statement)

printf("\n\t\t   BECOME A MILLIONAIRE!!!!!!!!!!!    ") ; (print statement)

printf("\n\t\t________________________________________"); (print statement)

printf("\n\t\t________________________________________"); (print statement)

printf("\n\t\t > Press S to start the game"); (print statement)

printf("\n\t\t > Press V to view the highest score  "); (print statement)

printf("\n\t\t > Press R to reset score"); (print statement)

printf("\n\t\t > press H for help            "); (print statement)

printf("\n\t\t > press Q to quit             "); (print statement)
    printf("\n\t\t________________________________________\n\n"); (print statement)

choice=toupper(getch()); (toupper function takes a single argument like "ch" - a character & getch() is a nonstandard function which is present in conio.h header file)

if (choice=='V') (if function)

{ (brace open)

show_record(); 

goto mainhome; (goto the mainhome function)

} (brace close)

else if (choice=='H') (else if function used)

{ (brace open)

help();getch(); (getch() is a nonstandard function which is present in conio.h header file)

goto mainhome; (goto the mainhome function)

} (brace close)

else if (choice=='R') (else if function used)

{ (brace open)

reset_score(); 

getch(); (getch() is a nonstandard function which is present in conio.h header file)


goto mainhome;

} (brace close)

else if (choice=='Q') (else if function used)

exit(1); (exit value 1 statement)

else if(choice=='S') (else if function used)

{ (brace open)

system("cls");

printf("\n\n\n\n\n\n\n\n\n\n\t\t\tResister your name:"); (print statement)

gets(playername); (gets() function reads a line from stdin and stores it into the string pointed to by str)

system("cls");

 printf("\n ------------------  Welcome %s to C Program Quiz Game --------------------------",playername); (print statement)

printf("\n\n Here are some tips you might wanna know before playing:"); (print statement)

printf("\n -------------------------------------------------------------------------"); (print statement)

printf("\n >> There are 2 rounds in this Quiz Game,WARMUP ROUND & CHALLANGE ROUND"); (print statement)

printf("\n >> In warmup round you will be asked a total of 3 questions to test your"); (print statement)

printf("\n    general knowledge. You are eligible to play the game if you give atleast 2"); (print statement)

printf("\n    right answers, otherwise you can't proceed further to the Challenge Round."); (print statement)

printf("\n >> Your game starts with CHALLANGE ROUND. In this round you will be asked a"); (print statement)

printf("\n    total of 10 questions. Each right answer will be awarded $100,000!"); (print statement)

printf("\n    By this way you can win upto ONE MILLION cash prize!!!!!.........."); (print statement)

printf("\n >> You will be given 4 options and you have to press A, B ,C or D for the"); (print statement)

printf("\n    right option."); (print statement)

printf("\n >> You will be asked questions continuously, till right answers are given"); (print statement)

printf("\n >> No negative marking for wrong answers!"); (print statement)

printf("\n\n\t!!!!!!!!!!!!! ALL THE BEST !!!!!!!!!!!!!"); (print statement)

printf("\n\n\n Press Y  to start the game!\n"); (print statement)

printf("\n Press any other key to return to the main menu!");
    if (toupper(getch())=='Y') (print statement)

{ (brace open)

 goto home; (A goto statement provides an unconditional jump from the 'goto' to a labeled statement in the same function)

} (brace close)

else (else statement used)

{ (brace open)

goto mainhome; (A goto statement provides an unconditional jump from the 'goto' to a labeled statement in the same function)

system("cls");

} (brace close)

home:

system("cls");

count=0; (value of count is declared as 0)

for(i=1;i<=3;i++) (for loop used where i will start from 1 and it will continue upto 3 )

{ (brace open)

system("cls");

r1=i; (r1 value is declared as i)

switch(r1) (switch case starts)

{ (brace open)

case 1: (case 1 starts)

printf("\n\nWhich windows edition cant be added to domain?");

printf("\n\nA.Windows Pro\t\tB.Windows Starter\n\nC.Windows Ultimate\t\tD.None of the above");

if (toupper(getch())=='B') (if statement used)

{ (brace open)

printf("\n\nCorrect!!!");

count++;

getch(); (getch() is a nonstandard function which is present in conio.h header file)

break; (We can use the break statement to end processing of a particular labeled statement within the switch statement. It branches to the end of the switch statement)

} (brace close)

else (else statement used)

{ (brace open)

printf("\n\nWrong!!! The correct answer is B.Windows Starter"); (printf statement used)

getch(); (getch() is a nonstandard function which is present in conio.h header file)

break; (We can use the break statement to end processing of a particular labeled statement within the switch statement. It branches to the end of the switch statement)

} (brace close)

case 2: (case 2 starts)

printf("\n\n\nHow would you find out what your current login shell is?"); 

printf("\n\nA.cat /etc/shell\t\tB.ps | grep sshd\n\nC.Echo $ SHELL\t\tD.Cat /etc/current/shell");

if (toupper(getch())=='C') (if statement used)

{ (brace open)

printf("\n\nCorrect!!!"); 

count++;

getch(); (getch() is a nonstandard function which is present in conio.h header file)
break; (We can use the break statement to end processing of a particular labeled statement within the switch statement. It branches to the end of the switch statement)


} (brace close)

else (else statement used)
       
{ (brace open)

printf("\n\nWrong!!! The correct answer is C.Echo $ SHELL"); (printf statement used)

getch(); (getch() is a nonstandard function which is present in conio.h header file)

break; (We can use the break statement to end processing of a particular labeled statement within the switch statement. It branches to the end of the switch statement)

} (brace close)

case 3: (case 3 starts)

printf("\n\n\nPTR records are available in __________."); 

printf("\n\nA.Reverse Lookup Zone\t\tB.Forwarders\n\nC.Forward Lookup Zone\t\tD.None of the above");

if (toupper(getch())=='A') (if statement used)

{ (brace open)

printf("\n\nCorrect!!!");

count++;

getch(); (getch() is a nonstandard function which is present in conio.h header file)

break; (We can use the break statement to end processing of a particular labeled statement within the switch statement. It branches to the end of the switch statement)

} (brace close)
else (else statement used)

{ (brace open)

printf("\n\nWrong!!! The correct answer is A.Reverse Lookup Zone");
       
getch(); (getch() is a nonstandard function which is present in conio.h header file)
       
break; (We can use the break statement to end processing of a particular labeled statement within the switch statement. It branches to the end of the switch statement)

} (brace close)

} (brace close)

} (brace close)

if(count>=1) (if statement used)
{ (brace open)

goto test; (A goto statement provides an unconditional jump from the 'goto' to a labeled statement in the same function)

} (brace close)

else (else statement used)

{ (brace open)

system("cls");

printf("\n\nSORRY YOU ARE NOT ELIGIBLE TO PLAY THIS GAME, BETTER LUCK NEXT TIME"); (print statement used)
getch(); (getch() is a nonstandard function which is present in conio.h header file)
goto mainhome; (A goto statement provides an unconditional jump from the 'goto' to a labeled statement in the same function)
} (brace close)
     
test:
     
system("cls");
     
printf("\n\n\t*** CONGRATULATION %s you are eligible to play the Game ***",playername); (print statement used)
     
printf("\n\n\n\n\t!Press any key to Start the Game!"); (print statement used)
     
if(toupper(getch())=='p') (if statement used)
{ (brace open)

goto game; (A goto statement provides an unconditional jump from the 'goto' to a labeled statement in the same function)

} (brace close)

game:
     
countr=0;
     
for(i=1;i<=5;i++) (for statement used)
     
{

system("cls");
     
r=i;

     
switch(r) (another switch case statement used)
{ (brace open)
case 1: (case 1 starts)

printf("\n\nWhich of the following authentication exchanges password in encrypted manner?");
printf("\n\nA.Plain-text\t\tB.PAP\n\nC.NULL\t\tD.CHAP");
if (toupper(getch())=='D') (if statement used)
{ (brace open)

printf("\n\nCorrect!!!"); (print statement used)

countr++;

getch(); (getch() is a nonstandard function which is present in conio.h header file)

break; (We can use the break statement to end processing of a particular labeled statement within the switch statement. It branches to the end of the switch statement)

getch(); (getch() is a nonstandard function which is present in conio.h header file)

} (brace close)
else (else statement used)

{ (brace open)

printf("\n\nWrong!!! The correct answer is D.CHAP");

getch(); (getch() is a nonstandard function which is present in conio.h header file)

goto score; (A goto statement provides an unconditional jump from the 'goto' to a labeled statement in the same function)

break; (We can use the break statement to end processing of a particular labeled statement within the switch statement. It branches to the end of the switch statement)

} (brace close)

case 2: (case 2 starts)
printf("\n\n\nTransport layer aggregates data from different applications into a single stream before passing it to __________"); (printf statement used)
printf("\n\nA.data link layer\t\tB.physical layer\n\nC.network layer\t\tD.application layer");
if (toupper(getch())=='C') (if statement used)
{ (brace open)

printf("\n\nCorrect!!!"); (printf statement used)

countr++;

getch(); (getch() is a nonstandard function which is present in conio.h header file)

break; (We can use the break statement to end processing of a particular labeled statement within the switch 

} (brace closed)

else (else statement used)
       
{ (brace open)

printf("\n\nWrong!!! The correct answer is C.network layer");

getch(); (getch() is a nonstandard function which is present in conio.h header file)
      
goto score; (A goto statement provides an unconditional jump from the 'goto' to a labeled statement in the same function)

       
break; (We can use the break statement to end processing of a particular labeled statement within the switch statement. It branches to the end of the switch statement)
       
} (brace close)

case 3: (case 3 starts)
printf("\n\n\nIf IP address and Subnet  mask are different on P2P link, which phase of PPP identifies the issue?"); (printf statement used)

printf("\n\nA.NCP\t\tB.LCP\n\nC.Authentication\t\tD.None of the above");
(printf statement used)
if (toupper(getch())=='A') (if statement used)
{ (brace open)

printf("\n\nCorrect!!!"); (printf statement used)

countr++;

getch(); (getch() is a nonstandard function which is present in conio.h header file)

 
break; (We can use the break statement to end processing of a particular labeled statement within the switch statement. It branches to the end of the switch statement)

} (brace close)
else (else statement used)
       
{ (brace open)

printf("\n\nWrong!!! The correct answer is A.NCP"); (printf statement used)

getch(); (getch() is a nonstandard function which is present in conio.h header file)

goto score; (A goto statement provides an unconditional jump from the 'goto' to a labeled statement in the same function)

break; (We can use the break statement to end processing of a particular labeled statement within the switch statement. It branches to the end of the switch statement)

} (brace close)

} (brace close)

} (brace close)

score:
    
system("cls");

score=(float)countr*100000;

if(score>0.00 && score<1000000) (if statement used)

{ (brace open)
   
printf("\n\n\t\t**************** CONGRATULATION *****************"); (printf statement used)
     
printf("\n\t You won $%.2f",score); (printf statement used)

goto go; (A goto statement provides an unconditional jump from the 'goto' to a labeled statement in the same function)

} (brace close)

 
else if(score==1000000.00) (else if statement used)

{ (brace open)

printf("\n\n\n \t\t**************** CONGRATULATION ****************"); (printf statement used)
    
printf("\n\t\t\t\t YOU ARE A MILLIONAIRE!!!!!!!!!"); (printf statement used)
    
printf("\n\t\t You won $%.2f",score); (printf statement used)
    
printf("\t\t Thank You!!"); (printf statement used)

} (brace close)
 
else (else statement used)

{ (brace open)
 
printf("\n\n\t******** SORRY YOU DIDN'T WIN ANY CASH ********"); (printf statement used)

printf("\n\t\t Thanks for your participation"); (printf statement used)

printf("\n\t\t TRY AGAIN"); (printf statement used)

goto go; (A goto statement provides an unconditional jump from the 'goto' to a labeled statement in the same function)

} (brace close)

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(getch())=='Y') (if statement used)

goto home; (A goto statement provides an unconditional jump from the 'goto' to a labeled statement in the same function)

else (else statement used)

{ (brace open)

edit_score(score,playername);

goto mainhome; (A goto statement provides an unconditional jump from the 'goto' to a labeled statement in the same function)

} (brace close)

} (brace close)

} (brace close)

void show_record() (void function used)

{ (brace open)

system("cls");

char name[20]; (character name is declared with a value 20)

float scr; (variable declared)

FILE *f;

f=fopen("score.txt","r");

fscanf(f,"%s%f",&name,&scr);

printf("\n\n\t\t*************************************************************"); (printf statement used)
printf("\n\n\t\t %s has secured the Highest Score %0.2f",name,scr); (printf statement used)

printf("\n\n\t\t*************************************************************"); (printf statement used)

fclose(f);

getch(); (getch() is a nonstandard function which is present in conio.h header file)

} (brace close)

void reset_score()

{ (brace open)

system("cls");

float sc; (variable declared)

char nm[20]; (character nm is declared with a value 20)

FILE *f;

f=fopen("score.txt","r+");

fscanf(f,"%s%f",&nm,&sc);

sc=0;

fprintf(f,"%s,%.2f",nm,sc);
   
fclose(f);

} (brace close)

void help()

{

system("cls");
    
printf("\n\n                              HELP"); (printf statement used)
    
printf("\n -------------------------------------------------------------------------"); (printf statement used)
    
printf("\n ......................... C program Quiz Game..........."); (printf statement used)
    
printf("\n >> There are two rounds in the game, WARMUP ROUND & CHALLANGE ROUND"); (printf statement used)
    
printf("\n >> In warmup round you will be asked a total of 3 questions to test your general"); (printf statement used)
    
printf("\n    knowledge. You will be eligible to play the game if you can give atleast 2"); (printf statement used)
    
printf("\n    right answers otherwise you can't play the Game..........."); (printf statement used)
    
printf("\n >> Your game starts with the CHALLANGE ROUND. In this round you will be asked"); (printf statement used)
    
printf("\n    total 3 questions each right answer will be awarded $100,000."); (printf statement used)
    
printf("\n    By this way you can win upto ONE MILLION cash prize in USD..............."); (printf statement used)
    
printf("\n >> You will be given 4 options and you have to press A, B ,C or D for the"); (printf statement used)
    
printf("\n    right option"); (printf statement used)
    
printf("\n >> You will be asked questions continuously if you keep giving the right answers."); (printf statement used)
    
printf("\n >> No negative marking for wrong answers"); (printf statement used)

printf("\n\n\t*********************BEST OF LUCK*********************************"); (printf statement used)

printf("\n\n\t*****C PROGRAM QUIZ GAME is developed by CODE WITH C TEAM********"); (printf statement used)

} (brace closed)

void edit_score(float score, char plnm[20]) (variable declared)

{ (brace open)

system("cls");

float sc; (variable declared)
char nm[20]; (character nm is declared with a value 20)

FILE *f;

f=fopen("score.txt","r");

fscanf(f,"%s%f",&nm,&sc);

if (score>=sc) (if statement used)

{  (brace open)

sc=score; (sc value is declared as score)

 fclose(f);

f=fopen("score.txt","w");

fprintf(f,"%s\n%.2f",plnm,sc);

fclose(f);

} (brace close)

} (brace close)

Output
Go to compile and run on Dev C++

Then Press S to start the quiz

Then resister your name here 

Then press Y to start the quiz game

Option B is the correct answer

You have type the wrong option so it will show wrong answer and after that it will show the correct answer i.e. correct option i.e. option C

The correct answer is option A

You are eligible to play another game i.e. the next part of quiz game -> Press any key to start the game

Option D is the correct answer

Option C is the correct answer



You have type the wrong option so it will show wrong answer and after that it will show the correct answer i.e. correct option i.e. option A

You won $200000.00 for giving two wrong answers -> If you want to play the next game then type Y otherwise if you want to quit and go the main menu then click on any key

You won $300000.00 for answering all the answers correctly





























Comments

Popular posts from this blog

Oxygen Cylinders Suppliers For Covid - 19 In India

TOP 10 IT COMPANIES IN INDIA