Title: Flash Cards
1Flash Cards
- Project 2 Wed, Oct 2, 2002
2Specific Problems
- How to control the number of problems.
- How to select the type of problem.
- How to create the numbers in the problem.
- How to compute the users score.
- How to evaluate his performance.
3How to Control the Number of Problems
- The user enters the number of problems that he
wants. - Use a for loop to control the presentation of
problems.
Prompt user for number of problems cin gtgt
numOfProblems for (int i 0 i lt numOfProblems
i) Present the next problem
4How to Select the Type of Problem
- Let i be the for loop control variable.
- Let the value of i, mod 4, represent the type of
problem (0 , 1 -, 2 , 3 /). - Use a switch statement, based on i 4, to select
the problem type.
5How to Select the Type of Problem
- Define symbolic constants for the cases of the
switch statement.
const int ADDITION 0 const int SUBTRACTION
1 const int MULTIPLICATION 2 const int
DIVISION 3
6How to Select the Type of Problem
switch (i 4) case ADDITION
Present an addition problem case
SUBTRACTION Present a subtraction
problem
7How to Create the Numbers in the Problem
- For addition and multiplication, use the
expression - 1 rand() 10
- to generate each number in the problem.
- For subtraction and division
- Use the above formula to select the second
operand and the answer. - Compute back to get the first operand.
8How to Create the Numbers in the Problem
- For example, suppose the problem is subtraction.
- Generate two random numbers, say 6 and 9.
- Let 6 be the second operand and 9 be the answer.
- Compute the first operand 6 9 15.
- Present the user with the problem
- 15 6 ?
9How to Compute the Users Score
- Read the users guess.
- Use a two-way if statement to compare it to the
correct answer. - In the True-action, increment a counter that
counts the number of correct answers. - After the for loop is finished, use the number of
correct answers to compute the users score.
10How to Compute the Users Score
if (guess answer) Print a message
Count the correct answer else Print a
message
11How to Evaluate His Performance
- A switch statement is inappropriate since there
are too many possible values to check. - Use a multi-way if statement.
- Each case should test a range of values.
- The True-actions should print the appropriate
messages.