Javatpoint Logo
Javatpoint Logo

Quiz game in C

In this article, you will learn about the project dealing with a Quiz game constructed in C language. The Quiz game is all about general knowledge testing.

Methods or functions that are involved in the program:

  • 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.
  • high_score() method
    The method " high_score() " 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 us understand all the methods or function discussed above with their respective codes and their uses.

1. main()

An explanation for the above method or function:

The method " main() " is declared initially in which all the other functions are accessed depending on the input given by the user. This method is declared in such a way that if the user wants to start the game, then he should intimate the system that he want to start the game. Similarly, if he wants to have a look at the high scores, then he have to inform the system that he want to know the high score.

This complete process is done by using the switch case statements. If the user gives the input as 1, then the system will understand that the user wants to start the quiz game. If the user gives the input as 2, then the system will understand that the user wants to access all the high scores. If the user gives the input as 3, then the system will understand that the user wants to seek the help and then displays all the instructions required to play the quiz.

2. high_score()

An explanation for the above method or function:

The method " high_score() " is declared initially in which the high scores of the users who have played the quiz game previously can be accessed and all the scores will be displayed once after calling this method. Initially, a file is created in which all the scores of the previous players will be stored in such a way that the user can see all those scores. If the file is null, then the user will be sent a message that there are no previous games played. If the file is not null and has some stored data, then it means that there are some people who played the game previously.

So, all their scores which were high scores once will be displayed. After the scores being displayed on the screen, then the user will be asked to enter an input describing if he or she still wants to continue the game or exit. If the user desires to continue, then he or she must enter 1 as an input. If not, then he or she must enter 0 in order to exit from the game screen. This process is done by using the conditional statements, i.e., " if else statements ". In this way, the function " high_score() " works and figures out the previous high scores.

3. help()

An explanation for the above method or function:

The method " help() " is declared initially in which the rules that are supposed to be followed and the instructions that are required are clearly explained. This method is accessed by the user when he or she wants to know about the game and the instructions of the game. In this way, the method is used. As soon as the user accessed the method, then the method displays all rules and instructions of the game.

The instructions of the game includes the total number questions that are going to be asked within the game, the number of points given for a correct answer, the number of points that are deducted for every wrong answer, etc. This information is more than enough for any user if at all he or she wishes to play the game. If the user wants to exit from the game, he can directly enter 0 as an input within this method. If the user wants to start playing the game, then he is supposed to enter 1 as an input.

4. start()

The complete program can be constructed by merging all the methods that are discussed above and then forming a simpler program in order to construct a quiz game in C programming language.

The program that demonstrates the construction of the quiz game:

Output for the above program:

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






Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA