I am sorry. I cant call out the function. C++ keeps saying identifier not found.
Thank you so much!
Task:
1. Create a New Project and give your project the name Lab3b2.
2. Add a source file to your project, called RemainderTest.cpp.
3. Write a remainder test, which performs the following:
Computers are playing an increasing role in education. Write a program that will help an
elementary school students learn remainder calculation.
A) Use srand and rand to produce two positive one-digit integers in range 1 to 9.
B) The program should then prompt the user with a question, such as:
How much is the remainder of 6 divided by 7?
C) Now, ask the student to input the answer.
D) Next, the program checks the student’s answer. If it is correct, display the message “Very
Good!” and ask another remainder question. If the answer is wrong, display the message
“No. Please try again.” and let the student try the same question repeatedly until the
student finally gets it right.
E) A sentinel value -1 is used to indicate the end of the program.
(Note: Separate functions should be used to generate each new one-digit integers and
perform the checking. These functions should be called once when the application begins
execution.)
A sample screen display when the method is called is given below:
How much is the remainder of 1 divided by 8?
Enter your answer (-1 to exit): 1
Very Good!
How much is the remainder of 3 divided by 9?
Enter your answer (-1 to exit): 2
No. Please try again!
Enter your answer (-1 to exit): 3
Very Good!
How much is the remainder of 8 divided by 2?
Enter your answer (-1 to exit): -1
The input which is underlined is the user’s input to a question.
4. Compile your program and test it by executing your program.
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 49 50 51 52 53 54 55
|
#include <iostream>
#include <ctime>
using namespace std;
void quiz()
{
int guess;
int number1, number2, answer;
int counter = 1;
bool flag = true;
do
{
if(flag){
// Pass two variables, number1 and number2, to function "generateQuestionAndAnswer"
// The function will return back the answer of the remainder.
// Hint: The variables should be PASSED BY REFERENCE
answer = generateQuestionAndAnswer(number1, number2);
cout << "How much is the remainder of " << number1 << " divided by " << number2 << "?" << endl;
}
cout << "Enter your answer (-1 to exit): ";
cin >> guess;
if( guess == -1 )
break;
// Pass two variables, guess and answer, to function "answerCorrect".
// The function will return a boolean value true if guess is equal to answer,
// otherwise, a boolean value false should be returned
flag = answerCorrect( guess, answer );
if(!flag)
cout << "No. Please try again." << endl;
else
cout << "Very good!" << endl;
}while( guess != -1 );
}
int generateQuestionAndAnswer( int a, int b ) { /* PASS-BY-REFERENCE */
a % b ;
}
int answerCorrect( int c, int d ) { /* PASS-BY-REFERENCE */
return (c = d) ? true : false;
}
int main()
{
srand((unsigned int)time(NULL));
quiz();
system("pause");
return 0;
}
|