Quiz Game In C

  • main method The method " main " is a function that gives all the options that can be explored in the entire program is main method. If the user wants to start the game, then he or she should visit the main method first and then through the main method, he or she should access the start method where all the questions related to the quiz will be available and then the user can start playing the Quiz game.
  • start method The method " start " is a function that consists of the complete questionnaire and the related answers of the quiz game so that the user will be allowed to play the game. This method should be constructed in a way that each question has its own and separate answer so that the other questions' answers will not overlap or replace. This method must be designed very carefully. If the answer is correct, the user will be awarded with 5 more points. If the answer is wrong, then no points will be deducted but the correct answer for that respective question will be displayed on the screen.
  • help method The method " help " is a function that gives the player a brief knowledge about the rules of the game and guides him or her by giving the required instructions. It describes about the number of questions present within the entire quiz, the points that are given for a right answer, and about the negative marking whenever the given answer is wrong. In this way, all the details and instructions of the quiz game are explained in detail.
  • highscore method The method " highscore " is a function that displays the high score up till then. The highest score out of all the games played will be recorded by this method in order to have score recordings. If the user crosses the previous high score with his score, then the user's score will be recorded as the new high score and the same score will be reflected in the further games also.

Let's explore each of the methods or functions mentioned earlier along with their corresponding code examples and purposes.

1. main

Example

// declare main method
void main()  
{  
    // clear screen statement
    clrscr();
    // choice variable is declared
    // in order to know the choice of the user
    int choice = 0;  
    printf( " Please enter 1 to start the game \n " );
    printf( " Please enter 2 to the high scores \n" );
    printf( " Please enter 3 to seek help \n" );
    printf( " Please enter 0 to exit \n" );
    printf( " Enter your choice: " );
    
    scanf( " %d ", &choice );  
    
    // switch statement is used
    // in order to consider multiple
    // options at a time
    // and choose one option
    // given by the user
    switch(choice)  
    {  
        // in order to start the game
        case 1:  
        start();  
        break;  

        // in order to see the high scores
        case 2:  
        high_score();  
        break;  

        // in order to seek help
        case 3:  
        help();  
        break;  

        // in order to exit
        default:  
        exit(1);  
    }  
  
  getch();  
}

An explanation for the above method or function:

The " main " function is initially defined to access all other functions based on user input. This function is structured so that the user must indicate to the system their desire to start the game in order to initiate gameplay. Likewise, if the user wishes to view the high scores, they must notify the system of their intent to see the high score list.

This entire procedure is carried out through the utilization of switch case statements. When the user inputs 1, the system interprets it as a request to initiate the quiz game. In the case of the user entering 2, the system infers that the user intends to view all the top scores. Upon inputting 3, the system recognizes the user's desire for assistance and proceeds to present all the necessary guidelines for engaging in the quiz.

2. high_score

Example

// method declared in order
// to find the latest high
// score
void high_score()  
{

  // declare the required variables
  // the variable " ch " is used
  // in order to choose between
  // continuing with the game
  // or to exit
  // by the user
  int ch;  
  
  // create a file
  // to extract and store
  // the details of 
  // the high scores
  FILE *fa;  
  if( ( fa = fopen("\\tmp\play2.txt", "r" ) ) == NULL )  
  {  
    printf( "\n There are no games played !!\n " );  
  }  
  else  
  {  
    printf( "\n Printing the high scores now !! \n\n " );  
    printf(" Name     Points_Scored     Rating\n " );  
    while(fscanf(fa," %s %d %d", p.name, &p.score, &p.rat) != EOF )  
    {  
      printf( " .................................\n " );  
      printf( " %s     %d     %d star(s)\n\n ", p.name, p.score, p.rat );  
    }  
    // close the file 
    // that is opened initially by using close method
    fclose(fa);  
  
  }  
  printf("\n Do you still want to continue playing ? If yes, then press 1 !! Else, press 0 :  " );  
  scanf( "%d", &ch );  
  
  // if the user wants to continue to play
  if( ch == 1 )  
  {  
    start();  
  }  

  // if the user wants to exit from the game
  else  
  {  
    exit(1);  
  }  
  
}

An explanation for the above method or function:

The function " high_score " is defined at the beginning to allow access to the high scores of users who participated in the quiz game before. By invoking this function, all the scores will be shown. A file is generated initially to store the scores of past players in a manner that allows users to view them. When the file is empty, a notification will inform the user that no previous games were played. Conversely, if the file contains data, it indicates that there are players who engaged in the game earlier.

So, any previous high scores will be shown on the screen. Following the display of scores, the user will receive a prompt to indicate whether they wish to keep playing or exit. To continue playing, the user needs to input 1. If they choose to exit, they should input 0 to leave the game screen. This functionality is achieved through the use of conditional statements, specifically, "if else statements". Through this method, the function "high_score" effectively identifies the past high scores.

3. help

Example

// method declared in order
// to provide help in the form
// of instructions to the user
// which describes about the rules
// and regulations to play
// the quiz game
void help()  
{  
    // declare the required
    // variables
    // the variable ch is used
    // in order to choose between
    // continuing with the game
    // or to exit
    // by the user
    int ch;  
  
    printf( "\n\n Instructions that are supposed to be followed " ); 
    printf("while playing this game: \n " );
    printf("Quiz Game in C\n " );
    printf("......................................................" )
     printf( "\n You are supposed to answer 20 questions in this game !! " );  
     printf( "\n There will be 4 options given for each questions which are marked with a serial number starting from 1 to 4. " );  
     printf( "\n For each correct answer, you will be awarded with 5 points !! " );  
     
     printf( "\n As soon as you answer a question, you will be directed to the next question without any pause. " );  
     printf( "\n If your answer is wrong, no marks will be deducted from your score !! " );  
  
    printf( "\n\n !! Wish you all the best !! \n\n " );  
  
  
    printf( "\n Do you still wish to continue playing ? If yes, then press 1. Else, press 0 :  " );  
    scanf( "%d", &ch );  
    
    // if the input given is 1
    if( ch == 1 )  
    {  
        start();  
    }  
    // if the input given is 0
    else  
    {  
        exit(1);  
    }  
  
}

An explanation for the above method or function:

The " help " function is primarily defined to outline the guidelines and provide necessary instructions for users. It serves as a resource for users seeking information about the game and its guidelines. When accessed, this function effectively presents all the rules and instructions pertinent to the game.

The game instructions specify the total count of questions in the game, the points awarded for correct answers, the points deducted for wrong answers, and other relevant details essential for players. This comprehensive information equips users with all necessary knowledge to engage in the game. To exit the game, users can input 0 directly within this function. Conversely, to commence gameplay, users are required to input 1.

4. start

Example

// method that is declared 
// in order to start the game
void start()  
{  
    // declare the required 
    // variables 

    // creating the variable
    // " ans " in order to 
    // store the answer given by
    // the user
    int ans; 

    // creating the variable
    // " count " in order to
    // store the number of 
    // questions that are correctly
    // answered by the user 
    int count = 0;  

    // creating the variable
    // " rating " in order to 
    // give the rating to
    // the user
    char rating[20];  
    
    // create a file
    // to store the records
    FILE *fa;  
  
    if( ( fa = fopen( "\\tmp\play2.txt","a" ) ) == NULL )  
    {  
        printf(" There is an error occurred while opening the file\n ");  
    }  
  
  
    printf( "\n Enter your Full name: " );  

    // scanning the 
    // name of the player
    scanf( "%s", p.name );  
  
    printf("\n You have entered the \"Quiz game in C\"");
    printf(" Welcome to the game \" %s \"   \n\n ", p.name);  
    
    printf(" The quiz game will be started now. Get ready to answer the questions !! \n ");
    printf(" ALL THE BEST !! ");
    
    printf(" Question 1: \n");
    printf(" In the following given characteristics, which one is not related to the federal government ? \n 1. Flexible Constitution \t \t 2. Written Constitution \t \t 3. Independent Judiciary \t \t 4. Supremacy of the Constitution \n\n ");  
  
    printf("Please enter your answer: ");  

    // scanning the answer
    // from the user
    scanf("%d", &ans);  
    
    // if the given answer 
    // is equal to 1, then the
    // answer is marked as a 
    // correct one and 5 points will
    // be given to the user
    if( ans == 1 )  
    {  
        printf(" Your answer is absolutely correct \n "); 
        printf(" You score 5 points !! \n\n ");
        ++count;  
    } 

    // if the given answer
    // is not equal to one,
    // then the answer is
    // marked as a wrong one
    // and marks will neither
    // be added nor be deducted 
    else  
    {  
        printf(" The answer that you have entered is wrong. The correct answer for the above question is option no.  1. Flexible Constitution \n\n");  
    }   
    
    printf(" Question 2: \n");
    printf(" In the following given members, who was the first person belonging to India entered into the space ? \n 1. Ravish Malhotra \t \t 2. Vikram Ambalal \t \t 3. Rakesh Sharma \t \t 4. Nagapathi Bhat \n\n ");  
  
    printf("Please enter your answer: ");  

    // scanning the answer
    // from the user
    scanf("%d", &ans);  
    
    // if the given answer 
    // is equal to 3, then the
    // answer is marked as a 
    // correct one and 5 points will
    // be given to the user
    if( ans == 3 )  
    {  
        printf(" Your answer is absolutely correct \n "); 
        printf(" You score 5 points !! \n\n ");
        ++count;  
    } 

    // if the given answer
    // is not equal to 3,
    // then the answer is
    // marked as a wrong one
    // and marks will neither
    // be added nor be deducted 
    else  
    {  
        printf(" The answer that you have entered is wrong. The correct answer for the above question is option no.  3. Rakesh Sharma  \n\n");  
    } 
    
    printf(" Question 3: \n");
    printf(" Who was the first women to reach the summits of all seven highest mountain peaks on every continent ? \n 1. Junko Tabei \t \t 2. Bachendri Pal \t \t 3. Premlata Agarwal \t \t 4. Santosh yadav \n\n ");  
  
    printf("Please enter your answer: ");  

    // scanning the answer
    // from the user
    scanf("%d", &ans);  
    
    // if the given answer 
    // is equal to 1, then the
    // answer is marked as a 
    // correct one and 5 points will
    // be given to the user
    if( ans == 1 )  
    {  
        printf(" Your answer is absolutely correct \n "); 
        printf(" You score 5 points !! \n\n ");
        ++count;  
    } 

    // if the given answer
    // is not equal to 1,
    // then the answer is
    // marked as a wrong one
    // and marks will neither
    // be added nor be deducted 
    else  
    {  
        printf(" The answer that you have entered is wrong. The correct answer for the above question is option no.  1. Junko Tabei  \n\n");  
    }
      
    printf(" Question 4: \n");
    printf(" Who was the first person to be the Indian Prime Minister ? \n 1. Prathiba Patel \t \t 2. Jawaharlal Nehru \t \t 3. Rabindranath Tagore \t \t 4. Lal Bahadur Shastri \n\n ");  
  
    printf("Please enter your answer: ");  

    // scanning the answer
    // from the user
    scanf("%d", &ans);  
    
    // if the given answer 
    // is equal to 2, then the
    // answer is marked as a 
    // correct one and 5 points will
    // be given to the user
    if( ans == 2 )  
    {  
        printf(" Your answer is absolutely correct \n "); 
        printf(" You score 5 points !! \n\n ");
        ++count;  
    } 

    // if the given answer
    // is not equal to 2,
    // then the answer is
    // marked as a wrong one
    // and marks will neither
    // be added nor be deducted 
    else  
    {  
        printf(" The answer that you have entered is wrong. The correct answer for the above question is option no.  2. Jawaharlal Nehru  \n\n");  
    }  
    printf(" Question 5: \n");
    printf(" How many bones does an adult human skeleton have ? \n 1. 207 bones \t \t 2. 205 bones \t \t 3. 206 bones \t \t 4. 210 bones \n\n ");  
  
    printf("Please enter your answer: ");  

    // scanning the answer
    // from the user
    scanf("%d", &ans);  
    
    // if the given answer 
    // is equal to 3, then the
    // answer is marked as a 
    // correct one and 5 points will
    // be given to the user
    if( ans == 3 )  
    {  
        printf(" Your answer is absolutely correct \n "); 
        printf(" You score 5 points !! \n\n ");
        ++count;  
    } 

    // if the given answer
    // is not equal to 3,
    // then the answer is
    // marked as a wrong one
    // and marks will neither
    // be added nor be deducted 
    else  
    {  
        printf(" The answer that you have entered is wrong. The correct answer for the above question is option no.  3. 206 bones  \n\n");  
    }
      
    printf(" Question 6: \n");
    printf(" Which blood group out of the following is known to be universal acceptor ? \n 1. AB + \t \t 2. AB - \t \t 3. O + \t \t 4. O - \n\n ");  
  
    printf("Please enter your answer: ");  

    // scanning the answer
    // from the user
    scanf("%d", &ans);  
    
    // if the given answer 
    // is equal to 1, then the
    // answer is marked as a 
    // correct one and 5 points will
    // be given to the user
    if( ans == 1 )  
    {  
        printf(" Your answer is absolutely correct \n "); 
        printf(" You score 5 points !! \n\n ");
        ++count;  
    } 

    // if the given answer
    // is not equal to 1,
    // then the answer is
    // marked as a wrong one
    // and marks will neither
    // be added nor be deducted 
    else  
    {  
        printf(" The answer that you have entered is wrong. The correct answer for the above question is option no.  1. AB +  \n\n");  
    }  
       
    
    printf(" Question 7: \n");
    printf(" What is Vitamin K also known as ? \n 1. Riboflavin \t \t 2. Thiamine \t \t 3. Ascorbic acid \t \t 4. Pentamine \n\n ");  
  
    printf("Please enter your answer: ");  

    // scanning the answer
    // from the user
    scanf("%d", &ans);   
    
    // if the given answer 
    // is equal to 3, then the
    // answer is marked as a 
    // correct one and 5 points will
    // be given to the user
    if( ans == 3 )  
    {  
        printf(" Your answer is absolutely correct \n "); 
        printf(" You score 5 points !! \n\n ");
        ++count;  
    } 

    // if the given answer
    // is not equal to 3,
    // then the answer is
    // marked as a wrong one
    // and marks will neither
    // be added nor be deducted 
    else  
    {  
        printf(" The answer that you have entered is wrong. The correct answer for the above question is option no.  3. Ascorbic acid  \n\n");  
    }
      
    printf(" Question 8: \n");
    printf(" Out of the following membranes, which membrane is mostly present in both Spinal cord and Brain ? \n 1. Meninges \t \t 2. Arachnoids \t \t 3. Plasma Membrane \t \t 4. Pleural membrane \n\n ");  
  
    printf("Please enter your answer: ");  

    // scanning the answer
    // from the user
    scanf("%d", &ans);  
    
    // if the given answer 
    // is equal to 1, then the
    // answer is marked as a 
    // correct one and 5 points will
    // be given to the user
    if( ans == 1 )  
    {  
        printf(" Your answer is absolutely correct \n "); 
        printf(" You score 5 points !! \n\n ");
        ++count;  
    } 

    // if the given answer
    // is not equal to 1,
    // then the answer is
    // marked as a wrong one
    // and marks will neither
    // be added nor be deducted 
    else  
    {  
        printf(" The answer that you have entered is wrong. The correct answer for the above question is option no.  1. Meninges  \n\n");  
    }
  
         
    
    printf(" Question 9: \n");
    printf(" Which person among the following people have contributed their time to represent the first budget of India after its Independence ? \n 1. Manmohan Singh \t \t 2. Jawaharlal Nehru \t \t 3. Pranav Mukherjee \t \t 4. R. K. Shanmukham Chetty \n\n ");  
  
    printf("Please enter your answer: ");  

    // scanning the answer
    // from the user
    scanf("%d", &ans);  
    
    // if the given answer 
    // is equal to 4, then the
    // answer is marked as a 
    // correct one and 5 points will
    // be given to the user
    if( ans == 4 )  
    {  
        printf(" Your answer is absolutely correct \n "); 
        printf(" You score 5 points !! \n\n ");
        ++count;  
    } 

    // if the given answer
    // is not equal to 4,
    // then the answer is
    // marked as a wrong one
    // and marks will neither
    // be added nor be deducted 
    else  
    {  
        printf(" The answer that you have entered is wrong. The correct answer for the above question is option no. 4. R. K. Shanmukham Chetty  \n\n");  
    }
      
    printf(" Question 10: \n");
    printf(" Which position out of the following has a right to select and appoint a Prime Minister ? \n 1. President \t \t 2. Chief Justice of India \t \t 3. Governor \t \t 4. Vice President \n\n ");  
  
    printf("Please enter your answer: ");  

    // scanning the answer
    // from the user
    scanf("%d", &ans);  
    
    // if the given answer 
    // is equal to 1, then the
    // answer is marked as a 
    // correct one and 5 points will
    // be given to the user
    if( ans == 1 )  
    {  
        printf(" Your answer is absolutely correct \n "); 
        printf(" You score 5 points !! \n\n ");
        ++count;  
    } 

    // if the given answer
    // is not equal to 1,
    // then the answer is
    // marked as a wrong one
    // and marks will neither
    // be added nor be deducted 
    else  
    {  
        printf(" The answer that you have entered is wrong. The correct answer for the above question is option no. 1. President  \n\n");  
    }

printf(" Question 11: \n");
    	printf(" The federal union country India consists of how many union territories ? \n 1. 6 \t \t 2. 7 \t \t 3. 8 \t \t 4. 9 \n\n ");  
  
    printf("Please enter your answer: ");  

    // scanning the answer
    // from the user
    scanf("%d", &ans);  
    
    // if the given answer 
    // is equal to 3, then the
    // answer is marked as a 
    // correct one and 5 points will
    // be given to the user
    if( ans == 3 )  
    {  
        printf(" Your answer is absolutely correct \n "); 
        printf(" You score 5 points !! \n\n ");
        ++count;  
    } 

    // if the given answer
    // is not equal to 3,
    // then the answer is
    // marked as a wrong one
    // and marks will neither
    // be added nor be deducted 
    else  
    {  
        printf(" The answer that you have entered is wrong. The correct answer for the above question is option no. 3. 8  \n\n");  
    }  
  
    printf(" Question 12: \n");
    printf(" Out of the following people, which person belonging to India  was the first one to win the Booker Price ? \n 1. Arundhati Roy \t \t 2. Aravind Adiga \t \t 3. Nirad C. Chaudhuri \t \t 4. Dhan Gopal Mukerji \n\n ");  
  
    printf("Please enter your answer: ");  

    // scanning the answer
    // from the user
    scanf("%d", &ans);  
    
    // if the given answer 
    // is equal to 1, then the
    // answer is marked as a 
    // correct one and 5 points will
    // be given to the user
    if( ans == 1 )  
    {  
        printf(" Your answer is absolutely correct \n "); 
        printf(" You score 5 points !! \n\n ");
        ++count;  
    } 

    // if the given answer
    // is not equal to 1,
    // then the answer is
    // marked as a wrong one
    // and marks will neither
    // be added nor be deducted 
    else  
    {  
        printf(" The answer that you have entered is wrong. The correct answer for the above question is 1. Arundhati Roy  \n\n");  
    }  
  
    printf(" Question 13: \n");
    printf(" Out of the following languages, which language is the mainly spoken language in the state Meghalaya ? \n 1. Khulu \t \t 2. Thayaari \t \t 3. Naasi \t \t 4. Khasi \n\n ");  
  
    printf("Please enter your answer: ");  

    // scanning the answer
    // from the user
    scanf("%d", &ans);  
    
    // if the given answer 
    // is equal to 4, then the
    // answer is marked as a 
    // correct one and 5 points will
    // be given to the user
    if( ans == 4 )  
    {  
        printf(" Your answer is absolutely correct \n "); 
        printf(" You score 5 points !! \n\n ");
        ++count;  
    } 

    // if the given answer
    // is not equal to 4,
    // then the answer is
    // marked as a wrong one
    // and marks will neither
    // be added nor be deducted 
    else  
    {  
        printf(" The answer that you have entered is wrong. The correct answer for the above question is option no. 4. Khasi \n\n");  
    }  
  
    printf(" Question 14: \n");
    printf(" How many number of judges do the Indian Supreme court consist of at present ? \n 1. 25 judges \t \t 2. 20 judges \t \t 3. 31 judges \t \t 4. 30 judges \n\n ");  
  
    printf("Please enter your answer: ");  

    // scanning the answer
    // from the user
    scanf("%d", &ans);  
    
    // if the given answer 
    // is equal to 3, then the
    // answer is marked as a 
    // correct one and 5 points will
    // be given to the user
    if( ans == 3 )  
    {  
        printf(" Your answer is absolutely correct \n "); 
        printf(" You score 5 points !! \n\n ");
        ++count;  
    } 

    // if the given answer
    // is not equal to 3,
    // then the answer is
    // marked as a wrong one
    // and marks will neither
    // be added nor be deducted 
    else  
    {  
        printf(" The answer that you have entered is wrong. The correct answer for the above question is 3. 32 Judges  \n\n");  
    }  
  
    printf(" Question 15: \n");
    printf(" Out of the following people, who was presented with the Union Budget for maximum number of times ? \n 1. R K Shanmukham Chetty \t \t 2.  P. Chidambaram \t \t 3. Pranav Mukherjee \t \t 4. Morarji Desai \n\n ");  
  
    printf("Please enter your answer: ");  

    // scanning the answer
    // from the user
    scanf("%d", &ans);  
    
    // if the given answer 
    // is equal to 4, then the
    // answer is marked as a 
    // correct one and 5 points will
    // be given to the user
    if( ans == 4 )  
    {  
        printf(" Your answer is absolutely correct \n "); 
        printf(" You score 5 points !! \n\n ");
        ++count;  
    } 

    // if the given answer
    // is not equal to 4,
    // then the answer is
    // marked as a wrong one
    // and marks will neither
    // be added nor be deducted 
    else  
    {  
        printf(" The answer that you have entered is wrong. The correct answer for the above question is option no. 4. Morarji Desai \n\n");  
    }
  
    printf(" Question 16: \n");
    printf(" Out of the following people, who is famously known as " flying sikh " ? \n 1. Milkha Singh \t \t 2.  Sardar Vallabhbhai Patel \t \t 3. Jawaharlal Nehru \t \t 4. Lala Lajpat Rai \n\n ");  
  
    printf("Please enter your answer: ");  

    // scanning the answer
    // from the user
    scanf("%d", &ans);  
    
    // if the given answer 
    // is equal to 1, then the
    // answer is marked as a 
    // correct one and 5 points will
    // be given to the user
    if( ans == 1 )  
    {  
        printf(" Your answer is absolutely correct \n "); 
        printf(" You score 5 points !! \n\n ");
        ++count;  
    } 

    // if the given answer
    // is not equal to 1,
    // then the answer is
    // marked as a wrong one
    // and marks will neither
    // be added nor be deducted 
    else  
    {  
        printf(" The answer that you have entered is wrong. The correct answer for the above question is option no. 1. Milkha Singh \n\n");  
    }  
  
    printf(" Question 17: \n");
    printf(" Out of the following days, when will the lunar eclipse happen ? \n 1. On a full moon night \t \t 2.  On a half moon night \t \t 3. On a Sunny day \t \t 4. On an Equinox \n\n ");  
  
    printf("Please enter your answer: ");  

    // scanning the answer
    // from the user
    scanf("%d", &ans);  
    
    // if the given answer 
    // is equal to 1, then the
    // answer is marked as a 
    // correct one and 5 points will
    // be given to the user
    if( ans == 1 )  
    {  
        printf(" Your answer is absolutely correct \n "); 
        printf(" You score 5 points !! \n\n ");
        ++count;  
    } 

    // if the given answer
    // is not equal to 1,
    // then the answer is
    // marked as a wrong one
    // and marks will neither
    // be added nor be deducted 
    else  
    {  
        printf(" The answer that you have entered is wrong. The correct answer for the above question is option no. 1. On a full moon night \n\n");  
    }  
    
    printf(" Question 18: \n");
    printf(" Out of the following listed cancers, which cancer is the most common type of cancer that kills male people in the entire world ? \n 1. Throat Cancer \t \t 2.  Lung Cancer \t \t 3. Liver Cancer \t \t 4. Skin Cancer \n\n ");  
  
    printf("Please enter your answer: ");  

    // scanning the answer
    // from the user
    scanf("%d", &ans);  
    
    // if the given answer 
    // is equal to 2, then the
    // answer is marked as a 
    // correct one and 5 points will
    // be given to the user
    if( ans == 2 )  
    {  
        printf(" Your answer is absolutely correct \n "); 
        printf(" You score 5 points !! \n\n ");
        ++count;  
    } 

    // if the given answer
    // is not equal to 2,
    // then the answer is
    // marked as a wrong one
    // and marks will neither
    // be added nor be deducted 
    else  
    {  
        printf(" The answer that you have entered is wrong. The correct answer for the above question is option no. 2. Lung Cancer \n\n");  
    } 
  
    printf(" Question 19: \n");
    printf(" Out of the following listed cancers, which cancer occurs within the bone marrow ? \n 1. Sarcoma \t \t 2.  Myeloma \t \t 3. Leukemia \t \t 4. Lymphoma \n\n ");  
  
    printf("Please enter your answer: ");  

    // scanning the answer
    // from the user
    scanf("%d", &ans);  
    
    // if the given answer 
    // is equal to 3, then the
    // answer is marked as a 
    // correct one and 5 points will
    // be given to the user
    if( ans == 3 )  
    {  
        printf(" Your answer is absolutely correct \n "); 
        printf(" You score 5 points !! \n\n ");
        ++count;  
    } 

    // if the given answer
    // is not equal to 3,
    // then the answer is
    // marked as a wrong one
    // and marks will neither
    // be added nor be deducted 
    else  
    {  
        printf(" The answer that you have entered is wrong. The correct answer for the above question is option no. 3. Leukemia \n\n");  
    }
  
    printf(" Question 20: \n");
    printf(" Out of the following listed virus, which which virus is transmitted through the bite of animals, birds, and insects that are effected with any kind of infections? \n 1. Ebola virus \t \t 2.  Rabies virus \t \t 3. Flavi virus \t \t 4. All of the bove \n\n ");  
  
    printf("Please enter your answer: ");  

    // scanning the answer
    // from the user
    scanf("%d", &ans);  
    
    // if the given answer 
    // is equal to 4, then the
    // answer is marked as a 
    // correct one and 5 points will
    // be given to the user
    if( ans == 4 )  
    {  
        printf(" Your answer is absolutely correct \n "); 
        printf(" You score 5 points !! \n\n ");
        ++count;  
    } 

    // if the given answer
    // is not equal to 4,
    // then the answer is
    // marked as a wrong one
    // and marks will neither
    // be added nor be deducted 
    else  
    {  
        printf(" The answer that you have entered is wrong. The correct answer for the above question is option no. 4. All of the above \n\n");  
    }

Combining all the previously discussed methods will result in a comprehensive program for creating a quiz game using the C programming language.

The program that demonstrates the construction of the quiz game:

Example

#include<stdio.h>  
#include<stdlib.h>  
#include<conio.h>  
  
struct play 
{  
            char name[20];  
            int score;  
            int rat;       
}p;  
  
void high_score();  
void start();  
void help();  
  

// declare main method
void main()  
{  
    
    // choice variable is declared
    // in order to know the choice of the user
    int choice = 0;
    printf("  Please enter 1 to start the game \n ");
    printf(" Please enter 2 to the high scores \n ");
    printf(" Please enter 3 to seek help \n ");
    printf(" Please enter 0 to exit \n ");
    printf(" Enter your choice: ");
    
    scanf( "%d", &choice );  
    
    // switch statement is used
    // in order to consider multiple
    // options at a time
    // and choose one option
    // given by the user
    switch(choice)  
    {  
        // in order to start the game
        case 1:  
            start();  
            break;  

        // in order to see the high scores
        case 2:  
            high_score();  
            break;  

        // in order to seek help
        case 3: help();  
                break;  

        // in order to exit
        default: exit(1);  
    }  
  
  getch();  
}
// method declared in order
// to find the latest high
// score
void high_score()  
{

  // declare the required variables
  // the variable " ch " is used
  // in order to choose between
  // continuing with the game
  // or to exit
  // by the user
  int ch;  
  
  // create a file
  // to extract and store
  // the details of 
  // the high scores
  FILE *fa;  
  if( ( fa = fopen("\\tmp\play2.txt", "r" ) ) == NULL )  
  {  
    printf( "\n There are no games played !!\n " );  
  }  
  else  
  {  
    printf( "\n Printing the high scores now !! \n\n " );  
    printf(" Name     Points_Scored     Rating\n " );  
    while(fscanf(fa," %s %d %d", p.name, &p.score, &p.rat) !=EOF )  
    {  
      printf( " .................................\n " );  
      printf( " %s     %d     %d star(s)\n\n ", p.name,p.score, p.rat );  
    }  
    // close the file 
    // that is opened initially by using close method
    fclose(fa);  
  
  }  
  printf("\n Do you still want to continue playing ? If yes,then press 1 !! Else, press 0 :  " );  
  scanf( "%d", &ch );  
  
  // if the user wants to continue to play
  if( ch == 1 )  
  {  
    start();  
  }  

  // if the user wants to exit from the game
  else  
  {  
    exit(1);  
  }  
  
}
// method declared in order
// to provide help in the form
// of instructions to the user
// which describes about the rules
// and regulations to play
// the quiz game
void help()  
{  
    // declare the required
    // variables
    // the variable ch is used
    // in order to choose between
    // continuing with the game
    // or to exit
    // by the user
    int ch;  
  
    printf( "\n\n Instructions that are supposed to be followed" ); 
    printf("while playing this game: \n " );
    printf("Quiz Game in C\n " );
    printf("......................................................" );
     printf( "\n You are supposed to answer 20 questions in this game !! " );  
     printf( "\n There will be 4 options given for each questions which are marked with a serial number starting from 1 to 4. " );  
     printf( "\n For each correct answer, you will be awarded with 5 points !! " );  
     
     printf( "\n As soon as you answer a question, you will be directed to the next question without any pause. " );  
     printf( "\n If your answer is wrong, no marks will be deducted from your score !! " );  
  
    printf( "\n\n !! Wish you all the best !! \n\n " );  
  
  
    printf( "\n Do you still wish to continue playing ? If yes, then press 1. Else, press 0 :  " );  
    scanf( "%d", &ch );  
    
    // if the input given is 1
    if( ch == 1 )  
    {  
        start();  
    }  
    // if the input given is 0
    else  
    {  
        exit(1);  
    }  
  
}
// method that is declared 
// in order to start the game
void start()  
{  
    // declare the required 
    // variables 

    // creating the variable
    // " ans " in order to 
    // store the answer given by
    // the user
    int ans; 

    // creating the variable
    // " count " in order to
    // store the number of 
    // questions that are correctly
    // answered by the user 
    int count = 0;  

    // creating the variable
    // " rating " in order to 
    // give the rating to
    // the user
    char rating[20];  
    
    // create a file
    // to store the records
    FILE *fa;  
  
    if((fa=fopen("\\tmp\play2.txt","a"))==NULL)  
    {  
        printf(" There is an error occurred while opening thefile\n ");  
    }  
  
  
    printf( "\n Enter your Full name: " );  

    // scanning the 
    // name of the player
    scanf( "%s", p.name );  
  
    printf("\n You have entered the \"Quiz game in C\"");
    printf(" Welcome to the game \" %s \"   \n\n ", p.name); 
    
    printf(" The quiz game will be started now. Get ready to answer the questions !! \n ");
    printf(" ALL THE BEST !! ");
    
    printf(" Question 1: \n");
    printf(" In the following given characteristics, which one is not related to the federal government ? \n 1. Flexible Constitution \t \t 2. Written Constitution \t \t 3. Independent Judiciary \t \t 4. Supremacy of the Constitution \n\n ");  
  
    printf("Please enter your answer: ");  

    // scanning the answer
    // from the user
    scanf("%d", &ans);  
    
    // if the given answer 
    // is equal to 1, then the
    // answer is marked as a 
    // correct one and 5 points will
    // be given to the user
    if( ans == 1 )  
    {  
        printf(" Your answer is absolutely correct \n "); 
        printf(" You score 5 points !! \n\n ");
        ++count;  
    } 

    // if the given answer
    // is not equal to one,
    // then the answer is
    // marked as a wrong one
    // and marks will neither
    // be added nor be deducted 
    else  
    {  
        printf(" The answer that you have entered is wrong. The correct answer for the above question is option no.  1. Flexible Constitution \n\n");  
    }   
    
    printf(" Question 2: \n");
    printf(" In the following given members, who was the first person belonging to India entered into the space ? \n 1. Ravish Malhotra \t \t 2. Vikram Ambalal \t \t 3. Rakesh Sharma \t \t 4. Nagapathi Bhat \n\n ");  
  
    printf("Please enter your answer: ");  

    // scanning the answer
    // from the user
    scanf("%d", &ans);  
    
    // if the given answer 
    // is equal to 3, then the
    // answer is marked as a 
    // correct one and 5 points will
    // be given to the user
    if( ans == 3 )  
    {  
        printf(" Your answer is absolutely correct \n "); 
        printf(" You score 5 points !! \n\n ");
        ++count;  
    } 

    // if the given answer
    // is not equal to 3,
    // then the answer is
    // marked as a wrong one
    // and marks will neither
    // be added nor be deducted 
    else  
    {  
        printf(" The answer that you have entered is wrong. The correct answer for the above question is option no.  3. Rakesh Sharma  \n\n");  
    } 
    
    printf(" Question 3: \n");
    printf(" Who was the first women to reach the summits of all seven highest mountain peaks on every continent ? \n 1. Junko Tabei \t \t 2. Bachendri Pal \t \t 3. Premlata Agarwal \t \t 4. Santosh yadav \n\n ");  
  
    printf("Please enter your answer: ");  

    // scanning the answer
    // from the user
    scanf("%d", &ans);  
    
    // if the given answer 
    // is equal to 1, then the
    // answer is marked as a 
    // correct one and 5 points will
    // be given to the user
    if( ans == 1 )  
    {  
        printf(" Your answer is absolutely correct \n "); 
        printf(" You score 5 points !! \n\n ");
        ++count;  
    } 

    // if the given answer
    // is not equal to 1,
    // then the answer is
    // marked as a wrong one
    // and marks will neither
    // be added nor be deducted 
    else  
    {  
        printf(" The answer that you have entered is wrong. The correct answer for the above question is option no.  1. Junko Tabei  \n\n");  
    }
      
    printf(" Question 4: \n");
    printf(" Who was the first person to be the Indian Prime Minister ? \n 1. Prathiba Patel \t \t 2. Jawaharlal Nehru \t \t 3. Rabindranath Tagore \t \t 4. Lal Bahadur Shastri \n\n ");  
  
    printf("Please enter your answer: ");  

    // scanning the answer
    // from the user
    scanf("%d", &ans);  
    
    // if the given answer 
    // is equal to 2, then the
    // answer is marked as a 
    // correct one and 5 points will
    // be given to the user
    if( ans == 2 )  
    {  
        printf(" Your answer is absolutely correct \n "); 
        printf(" You score 5 points !! \n\n ");
        ++count;  
    } 

    // if the given answer
    // is not equal to 2,
    // then the answer is
    // marked as a wrong one
    // and marks will neither
    // be added nor be deducted 
    else  
    {  
        printf(" The answer that you have entered is wrong. The correct answer for the above question is option no.  2. Jawaharlal Nehru  \n\n");  
    }  
    printf(" Question 5: \n");
    printf(" How many bones does an adult human skeleton have ? \n 1. 207 bones \t \t 2. 205 bones \t \t 3. 206 bones \t \t 4. 210 bones \n\n ");  
  
    printf("Please enter your answer: ");  

    // scanning the answer
    // from the user
    scanf("%d", &ans);  
    
    // if the given answer 
    // is equal to 3, then the
    // answer is marked as a 
    // correct one and 5 points will
    // be given to the user
    if( ans == 3 )  
    {  
        printf(" Your answer is absolutely correct \n "); 
        printf(" You score 5 points !! \n\n ");
        ++count;  
    } 

    // if the given answer
    // is not equal to 3,
    // then the answer is
    // marked as a wrong one
    // and marks will neither
    // be added nor be deducted 
    else  
    {  
        printf(" The answer that you have entered is wrong. The correct answer for the above question is option no.  3. 206 bones  \n\n");  
    }
      
    printf(" Question 6: \n");
    printf(" Which blood group out of the following is known to be universal acceptor ? \n 1. AB + \t \t 2. AB - \t \t 3. O + \t \t 4. O - \n\n ");  
  
    printf("Please enter your answer: ");  

    // scanning the answer
    // from the user
    scanf("%d", &ans);  
    
    // if the given answer 
    // is equal to 1, then the
    // answer is marked as a 
    // correct one and 5 points will
    // be given to the user
    if( ans == 1 )  
    {  
        printf(" Your answer is absolutely correct \n "); 
        printf(" You score 5 points !! \n\n ");
        ++count;  
    } 

    // if the given answer
    // is not equal to 1,
    // then the answer is
    // marked as a wrong one
    // and marks will neither
    // be added nor be deducted 
    else  
    {  
        printf(" The answer that you have entered is wrong. The correct answer for the above question is option no.  1. AB +  \n\n");  
    }  
       
    
    printf(" Question 7: \n");
    printf(" What is Vitamin K also known as ? \n 1. Riboflavin \t \t 2. Thiamine \t \t 3. Ascorbic acid \t \t 4. Pentamine \n\n ");  
  
    printf("Please enter your answer: ");  

    // scanning the answer
    // from the user
    scanf("%d", &ans);   
    
    // if the given answer 
    // is equal to 3, then the
    // answer is marked as a 
    // correct one and 5 points will
    // be given to the user
    if( ans == 3 )  
    {  
        printf(" Your answer is absolutely correct \n "); 
        printf(" You score 5 points !! \n\n ");
        ++count;  
    } 

    // if the given answer
    // is not equal to 3,
    // then the answer is
    // marked as a wrong one
    // and marks will neither
    // be added nor be deducted 
    else  
    {  
        printf(" The answer that you have entered is wrong. The correct answer for the above question is option no.  3. Ascorbic acid  \n\n");  
    }
      
    printf(" Question 8: \n");
    printf(" Out of the following membranes, which membrane is mostly present in both Spinal cord and Brain ? \n 1. Meninges \t \t 2. Arachnoids \t \t 3. Plasma Membrane \t \t 4. Pleural membrane \n\n ");  
  
    printf("Please enter your answer: ");  

    // scanning the answer
    // from the user
    scanf("%d", &ans);  
    
    // if the given answer 
    // is equal to 1, then the
    // answer is marked as a 
    // correct one and 5 points will
    // be given to the user
    if( ans == 1 )  
    {  
        printf(" Your answer is absolutely correct \n "); 
        printf(" You score 5 points !! \n\n ");
        ++count;  
    } 

    // if the given answer
    // is not equal to 1,
    // then the answer is
    // marked as a wrong one
    // and marks will neither
    // be added nor be deducted 
    else  
    {  
        printf(" The answer that you have entered is wrong. The correct answer for the above question is option no.  1. Meninges  \n\n");  
    }
  
         
    
    printf(" Question 9: \n");
    printf(" Which person among the following people have contributed their time to represent the first budget of India after its Independence ? \n 1. Manmohan Singh \t \t 2. Jawaharlal Nehru \t \t 3. Pranav Mukherjee \t \t 4. R. K. Shanmukham Chetty \n\n ");  
  
    printf("Please enter your answer: ");  

    // scanning the answer
    // from the user
    scanf("%d", &ans);  
    
    // if the given answer 
    // is equal to 4, then the
    // answer is marked as a 
    // correct one and 5 points will
    // be given to the user
    if( ans == 4 )  
    {  
        printf(" Your answer is absolutely correct \n "); 
        printf(" You score 5 points !! \n\n ");
        ++count;  
    } 

    // if the given answer
    // is not equal to 4,
    // then the answer is
    // marked as a wrong one
    // and marks will neither
    // be added nor be deducted 
    else  
    {  
        printf(" The answer that you have entered is wrong. The correct answer for the above question is option no. 4. R. K. Shanmukham Chetty  \n\n");  
    }
      
    printf(" Question 10: \n");
    printf(" Which position out of the following has a right to select and appoint a Prime Minister ? \n 1. President \t \t 2. Chief Justice of India \t \t 3. Governor \t \t 4. Vice President \n\n ");  
  
    printf("Please enter your answer: ");  

    // scanning the answer
    // from the user
    scanf("%d", &ans);  
    
    // if the given answer 
    // is equal to 1, then the
    // answer is marked as a 
    // correct one and 5 points will
    // be given to the user
    if( ans == 1 )  
    {  
        printf(" Your answer is absolutely correct \n "); 
        printf(" You score 5 points !! \n\n ");
        ++count;  
    } 

    // if the given answer
    // is not equal to 1,
    // then the answer is
    // marked as a wrong one
    // and marks will neither
    // be added nor be deducted 
    else  
    {  
        printf(" The answer that you have entered is wrong. The correct answer for the above question is option no. 1. President  \n\n");  
    }

printf(" Question 11: \n");
        printf(" The federal union country India consists of how many union territories ? \n 1. 6 \t \t 2. 7 \t \t 3. 8 \t \t 4. 9 \n\n ");  
  
    printf("Please enter your answer: ");  

    // scanning the answer
    // from the user
    scanf("%d", &ans);  
    
    // if the given answer 
    // is equal to 3, then the
    // answer is marked as a 
    // correct one and 5 points will
    // be given to the user
    if( ans == 3 )  
    {  
        printf(" Your answer is absolutely correct \n "); 
        printf(" You score 5 points !! \n\n ");
        ++count;  
    } 

    // if the given answer
    // is not equal to 3,
    // then the answer is
    // marked as a wrong one
    // and marks will neither
    // be added nor be deducted 
    else  
    {  
        printf(" The answer that you have entered is wrong. The correct answer for the above question is option no. 3. 8  \n\n");  
    }  
  
    printf(" Question 12: \n");
    printf(" Out of the following people, which person belonging to India  was the first one to win the Booker Price ? \n 1. Arundhati Roy \t \t 2. Aravind Adiga \t \t 3. Nirad C. Chaudhuri \t \t 4. Dhan Gopal Mukerji \n\n ");  
  
    printf("Please enter your answer: ");  

    // scanning the answer
    // from the user
    scanf("%d", &ans);  
    
    // if the given answer 
    // is equal to 1, then the
    // answer is marked as a 
    // correct one and 5 points will
    // be given to the user
    if( ans == 1 )  
    {  
        printf(" Your answer is absolutely correct \n "); 
        printf(" You score 5 points !! \n\n ");
        ++count;  
    } 

    // if the given answer
    // is not equal to 1,
    // then the answer is
    // marked as a wrong one
    // and marks will neither
    // be added nor be deducted 
    else  
    {  
        printf(" The answer that you have entered is wrong. The correct answer for the above question is 1. Arundhati Roy  \n\n");  
    }  
  
    printf(" Question 13: \n");
    printf(" Out of the following languages, which language is the mainly spoken language in the state Meghalaya ? \n 1. Khulu \t \t 2. Thayaari \t \t 3. Naasi \t \t 4. Khasi \n\n "); 
  
    printf("Please enter your answer: ");  

    // scanning the answer
    // from the user
    scanf("%d", &ans);  
    
    // if the given answer 
    // is equal to 4, then the
    // answer is marked as a 
    // correct one and 5 points will
    // be given to the user
    if( ans == 4 )  
    {  
        printf(" Your answer is absolutely correct \n "); 
        printf(" You score 5 points !! \n\n ");
        ++count;  
    } 

    // if the given answer
    // is not equal to 4,
    // then the answer is
    // marked as a wrong one
    // and marks will neither
    // be added nor be deducted 
    else  
    {  
        printf(" The answer that you have entered is wrong. The correct answer for the above question is option no. 4. Khasi \n\n");  
    }  
  
    printf(" Question 14: \n");
    printf(" How many number of judges do the Indian Supreme court consist of at present ? \n 1. 25 judges \t \t 2. 20 judges \t \t 3. 31 judges \t \t 4. 30 judges \n\n ");  
  
    printf("Please enter your answer: ");  

    // scanning the answer
    // from the user
    scanf("%d", &ans);  
    
    // if the given answer 
    // is equal to 3, then the
    // answer is marked as a 
    // correct one and 5 points will
    // be given to the user
    if( ans == 3 )  
    {  
        printf(" Your answer is absolutely correct \n "); 
        printf(" You score 5 points !! \n\n ");
        ++count;  
    } 

    // if the given answer
    // is not equal to 3,
    // then the answer is
    // marked as a wrong one
    // and marks will neither
    // be added nor be deducted 
    else  
    {  
        printf(" The answer that you have entered is wrong. The correct answer for the above question is 3. 32 Judges  \n\n");  
    }  
  
    printf(" Question 15: \n");
    printf(" Out of the following people, who was presented with the Union Budget for maximum number of times ? \n 1. R K Shanmukham Chetty \t \t 2.  P. Chidambaram \t \t 3. Pranav Mukherjee \t \t 4. Morarji Desai \n\n ");  
  
    printf("Please enter your answer: ");  

    // scanning the answer
    // from the user
    scanf("%d", &ans);  
    
    // if the given answer 
    // is equal to 4, then the
    // answer is marked as a 
    // correct one and 5 points will
    // be given to the user
    if( ans == 4 )  
    {  
        printf(" Your answer is absolutely correct \n "); 
        printf(" You score 5 points !! \n\n ");
        ++count;  
    } 

    // if the given answer
    // is not equal to 4,
    // then the answer is
    // marked as a wrong one
    // and marks will neither
    // be added nor be deducted 
    else  
    {  
        printf(" The answer that you have entered is wrong. The correct answer for the above question is option no. 4. Morarji Desai \n\n");  
    }  
  
    printf(" Question 16: \n");
    printf(" Out of the following people, who is famously known as \" flying sikh \" ? \n 1. Milkha Singh \t \t 2.  Sardar Vallabhbhai Patel \t \t 3. Jawaharlal Nehru \t \t 4. Lala Lajpat Rai \n\n ");  
  
    printf("Please enter your answer: ");  

    // scanning the answer
    // from the user
    scanf("%d", &ans);  
    
    // if the given answer 
    // is equal to 1, then the
    // answer is marked as a 
    // correct one and 5 points will
    // be given to the user
    if( ans == 1 )  
    {  
        printf(" Your answer is absolutely correct \n "); 
        printf(" You score 5 points !! \n\n ");
        ++count;  
    } 

    // if the given answer
    // is not equal to 1,
    // then the answer is
    // marked as a wrong one
    // and marks will neither
    // be added nor be deducted 
    else  
    {  
        printf(" The answer that you have entered is wrong. The correct answer for the above question is option no. 1. Milkha Singh \n\n");  
    }
  
    printf(" Question 17: \n");
    printf(" Out of the following days, when will the lunar eclipse happen ? \n 1. On a full moon night \t \t 2.  On a half moon night \t \t 3. On a Sunny day \t \t 4. On an Equinox \n\n ");    
    printf("Please enter your answer: ");  

    // scanning the answer
    // from the user
    scanf("%d", &ans);  
    
    // if the given answer 
    // is equal to 1, then the
    // answer is marked as a 
    // correct one and 5 points will
    // be given to the user
    if( ans == 1 )  
    {  
        printf(" Your answer is absolutely correct \n "); 
        printf(" You score 5 points !! \n\n ");
        ++count;  
    } 

    // if the given answer
    // is not equal to 1,
    // then the answer is
    // marked as a wrong one
    // and marks will neither
    // be added nor be deducted 
    else  
    {  
        printf(" The answer that you have entered is wrong. The correct answer for the above question is option no. 1. On a full moon night \n\n");  
    }  
    
    printf(" Question 18: \n");
    printf(" Out of the following listed cancers, which cancer is the most common type of cancer that kills male people in the entire world ? \n 1. Throat Cancer \t \t 2.  Lung Cancer \t \t 3. Liver Cancer \t \t 4. Skin Cancer \n\n ");  
  
    printf("Please enter your answer: ");  

    // scanning the answer
    // from the user
    scanf("%d", &ans);  
    
    // if the given answer 
    // is equal to 2, then the
    // answer is marked as a 
    // correct one and 5 points will
    // be given to the user
    if( ans == 2 )  
    {  
        printf(" Your answer is absolutely correct \n "); 
        printf(" You score 5 points !! \n\n ");
        ++count;  
    } 

    // if the given answer
    // is not equal to 2,
    // then the answer is
    // marked as a wrong one
    // and marks will neither
    // be added nor be deducted 
    else  
    {  
        printf(" The answer that you have entered is wrong. The correct answer for the above question is option no. 2. Lung Cancer \n\n");  
    }
  
    printf(" Question 19: \n");
    printf(" Out of the following listed cancers, which cancer occurs within the bone marrow ? \n 1. Sarcoma \t \t 2.  Myeloma \t \t 3. Leukemia \t \t 4. Lymphoma \n\n ");  
  
    printf("Please enter your answer: ");  

    // scanning the answer
    // from the user
    scanf("%d", &ans);  
    
    // if the given answer 
    // is equal to 3, then the
    // answer is marked as a 
    // correct one and 5 points will
    // be given to the user
    if( ans == 3 )  
    {  
        printf(" Your answer is absolutely correct \n "); 
        printf(" You score 5 points !! \n\n ");
        ++count;  
    } 

    // if the given answer
    // is not equal to 3,
    // then the answer is
    // marked as a wrong one
    // and marks will neither
    // be added nor be deducted 
    else  
    {  
        printf(" The answer that you have entered is wrong. The correct answer for the above question is option no. 3. Leukemia \n\n");  
    }
  
    printf(" Question 20: \n");
    printf(" Out of the following listed virus, which virus is transmitted through the bite of animals, birds, and insects that are effected with any kind of infections? \n 1. Ebola virus \t \t 2.  Rabies virus \t \t3. Flavi virus \t \t 4. All of the bove \n\n ");  
  
    printf("Please enter your answer: ");  

    // scanning the answer
    // from the user
    scanf("%d", &ans);  
    
    // if the given answer 
    // is equal to 4, then the
    // answer is marked as a 
    // correct one and 5 points will
    // be given to the user
    if( ans == 4 )  
    {  
        printf(" Your answer is absolutely correct \n "); 
        printf(" You score 5 points !! \n\n ");
        ++count;  
    } 

    // if the given answer
    // is not equal to 4,
    // then the answer is
    // marked as a wrong one
    // and marks will neither
    // be added nor be deducted 
    else  
    {  
        printf(" The answer that you have entered is wrong. The correct answer for the above question is option no. 4. All of the above \n\n");  
    } 
  
  
    // checking whether the user answered 
    // atleast one answer as
    // a correct answer 
    if(count > 0)  
    {  
        printf(" You have scored %d points \t \n", count * 5 );  
        printf(" Thank you for your interest !! \n");
        p.score = count * 5;  

        // giving the rating
        // to the user
        // based on his or her 
        // performance

        // if the score is
        // greater than or 
        // equal to 80,
        // the user will be
        // given 5 starred rating
        // or rating 5
        if( p.score >= 80 )  
        {  
            printf("Player rating: 5/5 \n");  
            p.rat = 5;  
        }  

        // if the score is
        // greater than or equal to 60,
        // and less than 80,
        // the user will be
        // given 4 starred rating
        // or rating 4
        else if( p.score >= 60 && p.score < 80 )  
        {  
            printf("Player rating: 4/5 \n");  
            p.rat = 4;  
        }  
        // if the score is
        // greater than or equal to 40,
        // and less than 60,
        // the user will be
        // given 3 starred rating
        // or rating 3
        else if(p.score >= 40 && p.score < 60)  
        {  
            printf("Player rating: 3/5 \n");  
            p.rat = 3;  
        }  

        // if the score is
        // greater than or equal to 20,
        // and less than 40,
        // the user will be
        // given 2 starred rating
        // or rating 2
        else if(p.score >= 20 && p.score < 40)  
        {  
            printf("Player rating: 2/5 \n");  
            p.rat = 2;  
        }  

        // if the score is
        // less than 20,
        // the user will be
        // given 1 starred rating
        // or rating 1
        else if(p.score < 20)  
        {  
            printf("Player rating: *");  
            p.rat = 1;  
        }  
  
        // printing all the details
        // which include name, 
        // score and rating  
  
        fprintf(fa, "%s %d %d", p.name, p.score, p.rat);  
        fclose(fa);  
    }  
    else  
    {  
        printf(" You have not answered any of the questions with correct answer !! Please try again\n");  
    }  
}

Output for the above program:

Output

Please enter 1 to start the game 
  Please enter 2 to the high scores
  Please enter 3 to seek help
  Please enter 0 to exit
  Enter your choice: 3

 Instructions that are supposed to be followed while playing this game:
 Quiz Game in C
 ......................................................
 You are supposed to answer 20 questions in this game !!
 There will be 4 options given for each questions which are marked with a serial number starting from 1 to 4. 
 For each correct answer, you will be awarded with 5 points !!
 As soon as you answer a question, you will be directed to the next question without any pause.
 If your answer is wrong, no marks will be deducted from your score !! 

 !! Wish you all the best !!

 Do you still wish to continue playing ? If yes, then press 1. Else, press 0 :  1

 Enter your Full name: Nikhitha

 You have entered the "Quiz game in C" Welcome to the game " Nikhitha "

  The quiz game will be started now. Get ready to answer the questions !!
  ALL THE BEST !!  Question 1:
 In the following given characteristics, which one is not related to the federal government ? 
 1. Flexible Constitution                2. Written Constitution                 3. Independent Judiciary                4. Supremacy of the Constitution       

 Please enter your answer: 1
 Your answer is absolutely correct
  You score 5 points !!

  Question 2:
 In the following given members, who was the first person belonging to India entered into the space ?
 1. Ravish Malhotra              2. Vikram Ambalal               3. Rakesh Sharma                4. Nagapathi Bhat 

 Please enter your answer: 3
 Your answer is absolutely correct
  You score 5 points !!

  Question 3:
 Who was the first women to reach the summits of all seven highest mountain peaks on every continent ? 
 1. Junko Tabei                  2. Bachendri Pal                3. Premlata Agarwal             4. Santosh yadav

 Please enter your answer: 1
 Your answer is absolutely correct
  You score 5 points !!

  Question 4:
 Who was the first person to be the Indian Prime Minister ?
 1. Prathiba Patel               2. Jawaharlal Nehru             3. Rabindranath Tagore                  4. Lal Bahadur Shastri 

 Please enter your answer: 2
 Your answer is absolutely correct
  You score 5 points !!

  Question 5:
 How many bones does an adult human skeleton have ?
 1. 207 bones            2. 205 bones            3. 206 bones            4. 210 bones

 Please enter your answer: 3
 Your answer is absolutely correct
  You score 5 points !!

  Question 6:
 Which blood group out of the following is known to be universal acceptor ?
 1. AB +                 2. AB -                 3. O +                  4. O - 

 Please enter your answer: 2
 The answer that you have entered is wrong. The correct answer for the above question is option no.  1. AB +

 Question 7:
 What is Vitamin K also known as ?
 1. Riboflavin           2. Thiamine             3. Ascorbic acid                4. Pentamine 

 Please enter your answer: 1
 The answer that you have entered is wrong. The correct answer for the above question is option no.  3. Ascorbic acid

 Question 8:
 Out of the following membranes, which membrane is mostly present in both Spinal cord and Brain ? 
 1. Meninges             2. Arachnoids           3. Plasma Membrane              4. Pleural membrane

 Please enter your answer: 1
 Your answer is absolutely correct
  You score 5 points !!

  Question 9:
 Which person among the following people have contributed their time to represent the first budget of India after its Independence ?
 1. Manmohan Singh               2. Jawaharlal Nehru             3. Pranav Mukherjee             4. R. K. Shanmukham Chetty 

 Please enter your answer: 2
 The answer that you have entered is wrong. The correct answer for the above question is option no. 4. R. K. Shanmukham Chetty

 Question 10:
 Which position out of the following has a right to select and appoint a Prime Minister ?
 1. President            2. Chief Justice of India               3. Governor             4. Vice President 

 Please enter your answer: 1
 Your answer is absolutely correct
  You score 5 points !!

  Question 11:
 The federal union country India consists of how many union territories ?
 1. 6            2. 7            3. 8            4. 9

 Please enter your answer: 3
 Your answer is absolutely correct
  You score 5 points !!

  Question 12:
 Out of the following people, which person belonging to India  was the first one to win the Booker Price ?
 1. Arundhati Roy                2. Aravind Adiga                3. Nirad C. Chaudhuri           4. Dhan Gopal Mukerji 

 Please enter your answer: 1
 Your answer is absolutely correct
  You score 5 points !!

  Question 13:
 Out of the following languages, which language is the mainly spoken language in the state Meghalaya ? 
 1. Khulu                2. Thayaari             3. Naasi                4. Khasi

 Please enter your answer: 1
 The answer that you have entered is wrong. The correct answer for the above question is option no. 4. Khasi

 Question 14:
 How many number of judges do the Indian Supreme court consist of at present ? 
 1. 25 judges            2. 20 judges            3. 31 judges            4. 30 judges

 Please enter your answer: 1
 The answer that you have entered is wrong. The correct answer for the above question is 3. 32 Judges

 Question 15:
 Out of the following people, who was presented with the Union Budget for maximum number of times ?
 1. R K Shanmukham Chetty                2.  P. Chidambaram              3. Pranav Mukherjee             4. Morarji Desai 

 Please enter your answer: 2
 The answer that you have entered is wrong. The correct answer for the above question is option no. 4. Morarji Desai

 Question 16:
 Out of the following people, who is famously known as " flying sikh " ?
 1. Milkha Singh                 2.  Sardar Vallabhbhai Patel            3. Jawaharlal Nehru             4. Lala Lajpat Rai 

 Please enter your answer: 1
 Your answer is absolutely correct
  You score 5 points !!

  Question 17:
 Out of the following days, when will the lunar eclipse happen ?
 1. On a full moon night                 2.  On a half moon night                3. On a Sunny day               4. On an Equinox 

 Please enter your answer: 1
 Your answer is absolutely correct
  You score 5 points !!

  Question 18:
 Out of the following listed cancers, which cancer is the most common type of cancer that kills male people in the entire world ?
 1. Throat Cancer                2.  Lung Cancer                 3. Liver Cancer                 4. Skin Cancer 

 Please enter your answer: 2
 Your answer is absolutely correct
  You score 5 points !!

  Question 19:
 Out of the following listed cancers, which cancer occurs within the bone marrow ?
 1. Sarcoma            2.  Myeloma             3. Leukemia             4. Lymphoma

 Please enter your answer: 3
 Your answer is absolutely correct
  You score 5 points !!

  Question 20:
 Out of the following listed virus, which virus is transmitted through the bite of animals, birds, and insects that are effected with any kind of infections?   
 1. Ebola virus                  2.  Rabies virus               3. Flavi virus           4. All of the above 

 Please enter your answer: 2
 The answer that you have entered is wrong. The correct answer for the above question is option no. 4. All of the above

 You have scored 65 points
 Thank you for your interest !!
Player rating: 4/5

Input Required

This code uses input(). Please provide values below: