Using Functions to create an arithmetical quiz

I am stil finding my way into functions in c++. I can't figure out how to sketch out the code for the below exercise. It has also been repeated to given as a practice exercise for us. Your precious help in helping me write this code would be grateful.....
The practice exercise specifications are as following:

The program will be a "quiz-er" for the user. he/she should be presented with a quiz of arithmetic problems. Each "play" of the quiz will be 10 questions. The user will initially be presented with a short menu of options on difficulty level. It could look something like this:

DIFFICULTY LEVEL

1. Easy
2. Moderate
3. Advanced
The difficulty levels determine the number of digits in the operands to be added or subtracted. Easy means only single digit numbers; moderate means double digit numbers; and advanced means 4-digit numbers. After the user picks the level they desire, your program presents problems that look like this:

45 + 9 = _
34 - 88 = _
etc
But for each problem presented, the user is given a chance to answer. If the answer is correct, another problem is presented. If the answer is wrong, the user is to be given one more chance at that problem. Once your program has moved on to the next problem, the correctness/incorrectness of the preceeding problem is tallied. The number of correct and incorrect answer is to be presented at the termination of the quiz along with percentage correct.
So, how are the problems produced? Well, you will use the random number generator provided by the compiler to determine:

1. the values to be added or subtracted
2. whether the problem is addition or subtraction

Remember: use the function srand() in your main to seed the generator and rand() to retrieve random numbers after that. Notes: (1) rand() returns a long int; and (2) pass time(NULL) as an argument to srand() and #include<ctime> to be able to use the system's time clock to seed the generator. I will speak in class about random numbers.


Here is a listing of the functions you are required to have in your program. You may include others if you see fit.
• a displayMenu function that has no parameters and returns a char
• a randomInt function that has 2 integer parameters (a minimum and a maximum) that returns a random integer between arguments min and max.
• a generateOperands function that returns nothing but has three parameters. One parameter represents the difficulty level (char). The other two are reference parameters representing the operands of the arithmetic problem that the next function will display.
• a displayProblem function that returns a long int (the answer that the user inputs) and has two parameters (the operands supplied by the preceding function. Note: In either this function or the preceding function, you will decide (randomly) whether the problem is an addition or subtraction problem.
• a isCorrect function that returns a bool and has three parameters. The parameters are the operands of the problem and the answer given by the user. The return value is determined in this function by whether or not the user's answer is correct or not for the given problem.
• a displayMessage function that returns nothing but outputs "correct" or "incorrect" dependent on the value returned by the preceding function.
• a displayFinalResults function that returns nothing and has two parameters: the number correct and the number wrong.


Once the user has finished the quiz, prompt them to see if they'd like to do it again. When you submit, play the quiz once and opt out of a second go round.
Topic archived. No new replies allowed.