Need help with the user friendly functions and how to ask the user if they want to play again.
The assignment:
An elementary school teacher is looking for a way to help students practice multiplication. You are asked to write a program that randomly chooses two positive one-digit integers (rand() function will be necessary). You then need to ask the student a multiplication question using these two integers:
How much is 6 times 7?
The student then types the answer. Your program checks the student's answer.
* If it is correct, call a user-written function [name it correct_response()] that will randomly choose and print one of the following responses:
Very Good!
Excellent!
Keep up the good work!
Nice Work!
Then ask the student another question.
* If it is incorrect call a user-written function [name it incorrect_response()] that will randomly choose and print one of the following responses:
No, please try again.
Wrong. Try once more.
Don't give up!
No. Keep trying.
Then let the student try the same question, again, repeatedly until the student gets the correct answer.
The student should be able to play the game until he/she decides to quit.
Do you want to play again? (enter 1 for yes or 2 for no)
Here is my code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
int main ()
{
int numbers[3];
srand ((unsigned)time(0));
int rn1 = rand() % 9 + 1; /* Random number 1 */
int rn2 = rand() % 9 + 1; /* Random number 2*/
int answer = rn1 * rn2;
/*required of user. */
cout << "\nThis program asks for a simple multiplication";
cout << "\nanswer from the user.";
cout << "\nPlease enter answer and press enter.";
/* while (answer == rn1 * rn2) */
while (1) /* loop until we break out */
{
cout << "\n\nHow much is " << rn1 << " times " << rn2 << " ? " << endl;
cin >> answer;
if (answer == rn1 * rn2)
{
case 0:
cout << "Very Good!"<< endl;
break;
case 1:
cout << "Excellent!" << end1;
break;
case 2:
cout << "Keep up the good work!" end1;
break;
default:
cout << "Nice Work!" <<end1;
break;
}
else
case 0:
cout<< "No. Please try again."<<endl;
case 1:
cout<< "Wrong. Try once more."<<endl;
case 2:
cout<< "Don't give up!"<<endl;
default:
cout<< "No. Keep trying."<<endl;
}
system ("pause";
return 0;
}
|
I also get the following errors:
(16) : error C2065: 'cout' : undeclared identifier
(17) : error C2065: 'cout' : undeclared identifier
(18) : error C2065: 'cout' : undeclared identifier
(23) : error C2065: 'cout' : undeclared identifier
(23) : error C2065: 'endl' : undeclared identifier
(24) : error C2065: 'cin' : undeclared identifier
(27) : error C2046: illegal case
(28) : error C2065: 'cout' : undeclared identifier
(28) : error C2065: 'endl' : undeclared identifier
(30) : error C2046: illegal case
(31) : error C2065: 'cout' : undeclared identifier
(31) : error C2065: 'end1' : undeclared identifier
(33) : error C2046: illegal case
(34) : error C2065: 'cout' : undeclared identifier
(34) : error C2146: syntax error : missing ';' before identifier 'end1'
(34) : error C2065: 'end1' : undeclared identifier
(36) : error C2047: illegal default
(37) : error C2065: 'cout' : undeclared identifier
(37) : error C2065: 'end1' : undeclared identifier
(41) : error C2046: illegal case
(42) : error C2065: 'cout' : undeclared identifier
(42) : error C2065: 'endl' : undeclared identifier
(43) : error C2046: illegal case
(44) : error C2065: 'cout' : undeclared identifier
(44) : error C2065: 'endl' : undeclared identifier
(45) : error C2046: illegal case
(46) : error C2065: 'cout' : undeclared identifier
(46) : error C2065: 'endl' : undeclared identifier
(47) : error C2047: illegal default
(48) : error C2065: 'cout' : undeclared identifier
(48) : error C2065: 'endl' : undeclared identifier
(50) : error C2143: syntax error : missing ')' before ';'