Right program that will help an elementary school student learn multiplication. Use rand (a built-in C under stdlib.h) to produce two positive 1-digit integers. It should type a question such as: How much is 6 times 7? The student type the answer. Your program checks the correct answer. An input of -1, the program will end. The ff. are the random comments. Responses to a correct answer: Very good, Excellent, Nice work, Keep up the good work. Responses to a wrong answer: No, please try again, Wrong, try once more, Don't give up, Keep on trying.
1
Expert's answer
2012-11-08T07:13:26-0500
#include <iostream> #include <conio.h> using namespace std; int main () { int first, second, result, userInput = 0; while (userInput != -1){ first = 1 + rand() % 10; second = 1 + rand() % 10; result = first * second; cout << first << " times "<< second << " = " ; cin >> userInput; int randComment = 0; if (userInput == result) { randComment = 1 + rand()% 4; if (randComment == 1){ cout << "Very good"<< endl; } if (randComment == 2){ cout << "Excellent"<< endl; } if (randComment == 3){ cout << "Nice work"<< endl; } if (randComment == 4){ cout << "Keep up the good work" << endl; } } else { randComment = 1 + rand()% 3; if (randComment == 1){ cout << "No, please try again" << endl; } if (randComment == 2){ cout << "Wrong, try once more" << endl; } if (randComment == 3){ cout << "Don't give up, Keep on trying" << endl; } } } system("pause"); return 0; }
Comments
Leave a comment