Using Visual Studios 2013 for desktop a) The use of computers in education is re
ID: 3761114 • Letter: U
Question
Using Visual Studios 2013 for desktop
a) The use of computers in education is referred to as computer-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 question.
This function should be called once when the application begins execution and each time the user answers the question correctly.
Explanation / Answer
#include <iostream>
#include <time.h>
using namespace std;
void generateQuestion(int &a, int &b) {
a=rand()%10;
b=rand()%10;
}
int main()
{
srand(time(NULL));
while (true) {
int a,b;
generateQuestion(a, b);
cout<<"What is "<<a<<" times "<<b<<": ";
int ans;
cin>>ans;
if (ans == a*b) {
cout<<" Very good! ";
} else {
do {
cout<<" No. Please try again! ";
cout<<"What is "<<a<<" times "<<b<<": ";
cin>>ans;
} while (ans != a*b);
cout<<" Very good! ";
}
}
cout<<" ";
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.