Streak counter

I am making a maths program and i need to show the longest streak of correct answers and also the longest streak of the incorrect answers.
how can i do this? I can only think of something like
1
2
3
4
5
int correct=0, incorrect = 0;
if (answer==result)
 correct++;
else 
 incorrect++;

the problem with that though it will only show the amount of answers that are correct and incorrect but will not actually find the longest streak.
Last edited on
What you have is a good start. Now make correct be the number of correct answers since the last incorrect answer and vice versa. Add variables to store the longest streak of correct and incorrect answers, and update them when needed.
how would i declare that though?
Make it like:
1
2
3
4
5
6
7
int LongerStreak = 0, CurrentStreak = 0;
if(answer == result)
    CurrentStreak++;
else
    CurrentStreak = 0;
if(CurrentStreak > LongerStreak)
    LongerStreak = CurrentStreak;

That's all of it for the Correct Streaks, Copy and Edit it for the Incorrect Streak!
Last edited on
This does not work for me. I have tried it but still it just shows the amount of correct and incorrect answers
So, show again the updated code? Probably you used if/else in a wrong way, let's see if I'm right.
EssGeEich:

1
2
3
4
5
[...]
else
    CurrentStreak = 0;
if(CurrentStreak > LongerStreak)
[...]


Just have to ask, did you make that on purpose or by accident?
Why is that wrong? Think, the declarations are made BEFORE his loop. There's no mistake.
oh lol, I nvm, I missed one thing.

I misread, my bad :P

I read it as "else if"... and somehow managed to get it as if answer != result, then currentstreak = 0 and after that - let's see if it's bigger than longerstreak!

Too much blood in my caffeine system.
Topic archived. No new replies allowed.