Need Help with Answer Counter and Unlock

So I'm trying to create a script that will unlock a physical box after a series of 3 simple math questions answered correctly. I managed to get the math portion down, but am running into problems trying to get the program to count the amount of correct answers. It simply has you re-enter the answer if you get it wrong and ends after all 3 are answered correctly.

this is the working code with just the math
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main ()
{ int MAX = 100; //3 Equations
int right_number;
int a;
int b;
int c;
int d;

srand(time (0));
a = 1 + rand() % MAX;
b = 1 + rand() % MAX;

cout <<" "<<endl<<endl<<endl;
cout <<" "<< a <<endl;
cout <<" "<< b <<endl;
cout <<"+____"<<endl;
cin >>right_number;
while (right_number != (a + b))
{
cout <<"Sorry, that's not it." << endl;
if (right_number < (a + b))
cout << "Try again.." << endl;
else
cout << "Try again.." << endl;
cin >> right_number;
}
srand(time (0));
c = 1 + rand() % MAX;
d = 1 + rand() % MAX;
cout <<" "<<endl<<endl<<endl;
cout <<" "<< c <<endl;
cout <<" "<< d <<endl;
cout <<"-____"<<endl;
cin >>right_number;
while (right_number != (c - d))
{
cout <<"Sorry, that's not it." << endl;
if (right_number < (c - d))
cout << "Try again.." << endl;
else
cout << "Try again.." << endl;
cin >> right_number;
}
{ int MAX = 20;
int right_number;
int a;
int b;
srand(time (0));
a = 1 + rand() % MAX;
b = 1 + rand() % MAX;
cout <<" "<<endl<<endl<<endl;
cout <<" "<< a <<endl;
cout <<" "<< b <<endl;
cout <<"X____"<<endl;
cin >>right_number;
while (right_number != (a * b))
if (right_number !=(a * b))
{
cout <<"Sorry, that's not it." << endl;
if (right_number < (a * b))
cout << "Try again.." << endl;
else
cout << "Try again.." << endl;
cin >> right_number;
}
}
}



Applying this to try and code it to unlock after it counts 3, and then to reset it after the lock is reset is beyond me. One step at a time though
Last edited on
Topic archived. No new replies allowed.