Compare last and current response

Hi,

Currently, I'm struggling with this comparison problem and I have been searching for solution for these past three days, but I can't seem to find an answer.

My problem is that I am trying to code the direction of the user's keyboard response. For example, if the user entered three consecutive correct responses the direction would changed to -1 (for down) and for every incorrect response the direction would change to 1 (for up). For every combination of 1 up and 1 down or 1 down and 1 up would constitute one reversal. And so right now I'm having a difficulty in coding one reversal because I don't know how to store the previous direction and then use it and compare with the current direction.

Thank you in advance for any help or advice anyone has to offer.

Hi, not sure if I got it right.

3x correct: direction = -1
3x incorrect: direction = 1

is this right?

If so (an idea):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
int correct = 0;
int wrong = 0;
int distance = 0;

loop...
if(correct){
correct++;
wrong = 0;}
else
wrong++;
correct = 0;}

if(correct%3 == 0 & correct != 0){
correct=0;
distance++;}

if(wrong%3 == 0 & wrong != 0){
wrong=0;
distance--;}

end loop...


A bit clumsy perhaps, and I did it pretty fast. I think it might work, though.
Store them in an array and then see if they equal eachother? Perhaps show the code you have already got...
Topic archived. No new replies allowed.