Saturday, March 28, 2020

Quiz Game in C Part 3: Final Game Play and score



In previous articles, we created functions, multi-dimensional character array to store questions, options, and answers. Up to this point, we have everything ready to finish gameplay.
Here we will use the following techniques:

  • Create for loop to display question one by one
  • Create another infinite loop inside for loop to check the answer given by the user. The loop breaks only if the user-provided an answer is within options (a, b, c and d)  otherwise it will loop infinitely. 
  • Calculate the score for the correct answer provided.
  • Use gotoxy to manage text indentation.

Quiz game in C Part 2: Multi-dimensional C array

Previous Page                                                                                                                    Next Page


In this article, we will discuss the gameplay() function but not all only the usages of one dimension, two-dimension, and third dimension character array. Choosing the correct dimension of the array is very important to store information effectively. We have to display a question, four options and store the correct answer to compare the answer provided by the user. Remember these three information are connected to each other if we mismatch the order then the game will go wrong. 
Here, we will declare three character array to store questions, four options, and answer in the same order of the array index.

Question is a string which is an array of character and we will ask 10 questions in total. We create a two-dimension character array, the first index is a total number of questions i.e 10 and the second index is the length of a string.
    char question[10][250];
    strcpy(question[0], "This is question no 1");
    strcpy(question[1], "This is question no 2");
    strcpy(question[2], "This is question no 3");
    strcpy(question[3], "This is question no 4");
    strcpy(question[4], "This is question no 5");
    strcpy(question[5], "This is question no 6");
    strcpy(question[6], "This is question no 7");
    strcpy(question[7], "This is question no 8");
    strcpy(question[8], "This is question no 9");
    strcpy(question[9], "This is question no 10");
We can't assign string using "=" to the two-dimension array and correct way to use it is strcpy() function.

Quiz Game in C part 1 - Flow Chart and Main Menu


Previous Page                                                                                                                           Next Page


Application Flow Chart:

Start: Quiz program start
Main Menu: Program display menu to the user to start the game or to quit.
User Input: The application stops to get user input.
Decision Tree: If user input is S then Quiz game start else if user input is Q then the program will quit.
Quiz Game: User gets 10 questions one by one and each correct score is marked as 1.
Display Score: It display final score after ending the game and the user is directed to the main menu.
Stop: End of the game.