Quiz Game in C

Quiz Games are one of the most interactive and mind blogging games of all time. Whether it be a child or teen or an adult, these Quiz Games fascinate people of all age groups. In this article, we will make a simple Quiz Game using C programming language.

Functionalities of a Quiz Game

The Quiz Game program provides the following functionalities:

Prerequisites: Basic knowledge of C, Control Statements, Arrays, Strings, Functions and Structures.

quiz game in c

Components of the Quiz Game Program

The Quiz Game program is made up of the following major components:

1. Header Files and Macro Definitions

2. Question Structure

A structure named “Question” is defined to represent a quiz question containing the following fields:

3. displayQuestion() Function

4. checkAnswer() Function

5. main() Function

6. Randomized Questions

Execution Flow of the Program

  1. The program greets the user and then enters a loop to ask questions.
  2. In each iteration of the loop:
    1. A random index is generated to select a question from the remaining pool of questions. Since we have used srand as discussed earlier.
    2. The selected question is displayed using the “displayQuestion” function.
    3. The user is prompted to enter their answer (1-4).
    4. The program checks if the answer is valid and within the range 1-4.
    5. If the answer is valid, it checks if it’s correct using the “checkAnswer” function and updates the user’s score accordingly.
    6. If the answer is incorrect, it displays the correct answer.
    7. If the answer is invalid, it prompts the user to enter a valid choice.
    8. The selected question is removed from the “questions” array by replacing it with the last question in the array, and “num_questions” is decremented.

    Overall, this program is determined to conduct a randomized quiz game with a fixed set of questions and multiple-choice answers to those questions. It provides feedback to the user on whether their answers are correct and keeps track of the score. The user’s score is displayed at the end of the quiz with a message.