This code implements a simple question and answer game using C language. It presents a set of multiple-choice questions to the user and evaluates their answers. The code includes a data structure to store the questions and their corresponding choices and correct answers.
The code can be summarized as follows:
- It includes necessary header files:
stdio.h
,unistd.h
, andctype.h
. - It defines a structure named
questions
to represent a question and its possible answers. - The
main
function starts the execution of the program. - It initializes an array of
questions
namedMCQ
with 20 predefined questions, choices, and correct answers. - Variables
nbr_right_ans
,score
,game_number
,answer
,count
, andQ_Aanswer
are declared. - The program displays a welcome message.
- It asks the user if they are ready to play the game.
- If the user enters 'n', the program ends. Otherwise, the game continues.
- The program iterates through each question in the
MCQ
array. - It displays the question and its choices to the user.
- The user enters their answer.
- The program checks if the answer is correct and updates the score accordingly.
- After answering all the questions, the program displays the number of games played, the score, and the number of correct answers.
- The program repeats the game loop until the user chooses to exit.
- If the user chooses to exit, the program displays a goodbye message and terminates.
To run the code, follow these steps:
- Compile the code using a C compiler.
- Execute the compiled program.
- Answer the questions by entering the corresponding choice number.
Contributions to the code are welcome. Feel free to submit a pull request or open an issue for any improvements or bug fixes.
For any inquiries or questions, you can reach out to the author at oussama oulaydi.