(Computer-Assisted Instruction) The use of computers in education is referred to as com- puter-assisted instruction (CAI). Write a program that will help an elementary school student learn multiplication. Use the rand function to produce two positive one-digit integers. The program should then prompt the user with a question, such as How much is 6 times 7? The student then inputs the answer.

Next, the program checks the student’s answer. If it’s correct, display the message "Very good!" and ask another multiplication 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. A separate function should be used to generate each new ques- tion. This function should be called once when the application begins execution and each time the user answers the question correctly.

What will be an ideal response?


```
// Help user practice multiplication.
#include
#include
#include
using namespace std;

int generateProblem(); // function prototype

int main()
{
int response = 0; // user response for product

srand( time( 0 ) ); // seed random number generator

// loop until sentinel value read from user
while ( response != -1 )
{
int answer = generateProblem(); // get product
cin >> response; // read user's guess

// loop until sentinel value or correct response
while ( response != -1 && response != answer )
{
cout << "No. Please try again." << endl << "? ";
cin >> response;
} // end while

// correct response
if ( response == answer )
cout << "Very good!" << endl << endl;
} // end while

cout << "That's all for now. Bye." << endl;
} // end main

// generates new product and displays prompt
int generateProblem()
{
int x = rand() % 10; // generate 1-digit random number
int y = rand() % 10; // generate 1-digit random number

cout << "How much is " << x << " times " << y << " (-1 to End)\n? ";

return x * y; // return product
```

Computer Science & Information Technology

You might also like to view...

A class-level variable ___________________.

a. is declared inside a class but outside any procedure b. is accessible to all procedures in a class c. is visible to all statements inside the class d. all of the above

Computer Science & Information Technology

Flash Fill is a function in Microsoft Excel used to enter formulas with multiple calculations.?

Answer the following statement true (T) or false (F)

Computer Science & Information Technology

Use ____ when you want to insert a worksheet into another program and retain a connection with the original document and the original program.

A. embedding B. inserting C. importing D. linking

Computer Science & Information Technology

Information produced and stored by a computer is called ______.

Fill in the blank(s) with the appropriate word(s).

Computer Science & Information Technology