ok. i have been working on my assignment since morning and i feel tiered and confused.
here is the assignment!
Computers have been used to test students on their ability to solve arithmetic problems. Write a program that will test a student on addition,substraction and multiplication using random integers between 10 and 100. The student has 3 chances to answer the problem correctly. If after 3 chances the answer is still incorrect, the correct answer is displayed. A score is calculated by awarding:
20:41:43
§ 10 points for a correct answer on the first try,
§ 5 points on the second try,
§ 2 points on the third try, and
§ 0 points if all three attempts are wrong.
20:42:03
Your program should have the following features:
20:42:20
§ Input the number of questions from the user.
§ Choose numbers randomly (between 10 and 100)
§ Choose operation randomly (addition, substraction or multiplication)
§ Display the total score earned by the student after each question.
§ Use at least 3 functions other than function main.
(Some grades will be allocated to the efficient choice of functions)
Regarding the random function selection aspect of the program; I would be inclined to write something like:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
int main() {
int randomchoice = 3 % rand(); // Assign random number 1-3
cout << randomchoice << endl; // DEBUG: Check value of random number - remove before submission
switch(randomchoice){ // Switchcase on said number
case 1:
addition(); // If 1; addition
break;
case 2:
subtraction(); // If 2; subtraction
break;
case 3:
multiplication(); // If 3; multiplication
break;
default:
cout << "ERROR: Input not an integral value from 1-3" << endl; // Standard output - shouldn't get printed
}
return 0;
}
HOWEVER the values don't seem to be random - I can get 110*110 more than 5 times in a row. Maybe it's my syntax; I've never used the rand() function before.