Design, 115 Program 4, Spring 2001

Phase I

Write the functions to do addition problems with the student

The main function
1. get student's id number
2. call add function with two arguments, problemCounter and correctCounter
3. call report function with idnumber, problemCounter and correctCounter

int getrand()
1. return rand() % 100;

Function add has to call getrand and return two numbers that represent the number of problems attempted and the number answered correctly. Since there are two numbers to return, they will have to be reference parameters.

1. initialize two counters

2. do 
3. 	use getrand() to get addend1 and addend2
4. 	increment the problem counter
5. 	display the 2 addends and the line underneath
		formatted right justified
6.	get the user's answer
7.	if answer is correct
		increment correct counter
8.	ask if the student wants to do it again
9.	get user's answer
10. while answer is yes

11. return two counters

report function
three parameters, student id, number attempted, number correct

1. report the values of the three parameters
2. calculate the percent correct and report that

Phase II

The menu function has no parameters and returns a character that is the user's choice.

1. do
2. 	display the 4 operation choices
3. 	get the user's choice
4. while choice is not valid (A,S,M,D,Q)
5. return the choice

Change the main function to:

1.  get student's id number
2.  call menu function
3.  based on user's choice 
	call a function to practice the chosen operation
4.  call report function with idnumber, problemCounter and correctCounter

The sub function will be like the add function except that it will make sure the problem answer is not a negative number. That can be done by:

    get num1 from getrand()
    get num2 from getrand()
while (num1 - num2 < 0)

    if num2 > num1
	swap the values of num1 and num2

multiply function will be just like the add function

divide function will be like the add function, except that it must make sure that the divisor is not zero and that the answer to the problem is a whole number. There are different ways to do that:

    get num1 from getrand()
    	get num2 from getrand()
    while num2 == 0
while (num1 % num2 != 0)

Phase III

int getDifficulty() will return the number the user input for the level of difficulty, should be from 1 to 5, inclusive.

1. do
2.	prompt for level
3.	get user's number
4. while number <1 or number > 5
5. return number

int getrand (int diff)
1.	return rand() % int(pow(10, diff));

All four operation functions will need another parameter, the difficulty level, and will use it when calling getrand. No other changes to the functions are needed

The main function will also need to ask the user for a seed for the random number generator, once, at the beginning of the program, and then call srand with that seed.