-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path6.56.cpp
More file actions
50 lines (37 loc) · 1.21 KB
/
6.56.cpp
File metadata and controls
50 lines (37 loc) · 1.21 KB
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
// Computer Assisted Instruction
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
inline int generateRandom(); // generate a random integer
int main(void){
// seed the random number generator
srand(time(NULL));
int rand1, rand2; // the two randomly generated numbers
int answer; // answer provided by the student
const int questionsToAsk = 10; // ask 10 questions from the student
bool askAgain = false; // check whether to ask again
rand1 = generateRandom();
rand2 = generateRandom();
for(int i=0; i<questionsToAsk; i++){
do{
cout << "How much is " << rand1 << " times " << rand2 << "?" << endl;
cin >> answer;
if (answer == rand1*rand2){
cout << "Very good!" << endl;
askAgain = false;
}else{
cout << "No. Please Try again" << endl;
askAgain = true;
}
}while(askAgain);
// Generate new numbers for the next question
rand1 = generateRandom();
rand2 = generateRandom();
}
return 0;
}
// Generate a random number between 1 and 20
inline int generateRandom(){
return 1 + rand() % 20;
}