- #1
gruba
- 206
- 1
Homework Statement
I need help with the following problem in C programming language:
Define a quiz and add two questions in it with given possible answers. Display the questions one by one and allow the user to choose between 1, 2 or 3 (numbers that represent serial numbers of possible answers). If the user enters the character which is not 1, 2 or 3, then allow the user to choose an answer again. At the end of the quiz, print the final score in percentage.
Use the following definitions:
Code:
#define MAX 1000000
typedef struct
{
char questionText[MAX];
char firstAnswer[MAX];
char secondAnswer[MAX];
char thirdAnswer[MAX];
int snca;//serial number of the correct answer (1, 2 or 3)
}QUESTION;
typedef struct
{
int tnq;//total number of questions
QUESTION *questions;
}QUIZ;
void addNewQuestion(QUIZ *qz,QUESTION *qn);//adds new question
void displayQuestion(QUIZ *qz,int snq);//prints question. 'snq' is the serial number of a question
int isCorrect(QUIZ *qz,int snq,int snqa);//checks if the chosen answer with the serial number 'snqa'
//on a question with the serial number 'snq' is correct
Code:
/*Example program:
1. In what year was the C programming language created?
1. 1845
2. 1832
3. 1972
Choose an answer: 3
2. Who is the author of C programming language?
1. Bill Gates
2. Dennis Ritchie
3. Steve Jobs
Choose an answer: 10
Error. Choose between 1, 2 or 3.
Choose an answer: 2
Final score: 100%*/
2. The attempt at a solution
I don't understand a couple of things in this problem:
1. How to add a question using the prototype function given above?
The function requires to only add one question, so do we need two separate functions for adding a question?
2. In the structure quiz, variable tnq which represents total number of questions is given. Why? It is said in the problem that the total number of questions is two, so the program should end after the user gives an answer to two questions, right?
Could someone explain this?