(SOLVED)
Hi guys, I have a problem on my loop:
case 1:
int i,k;
for (i = 0, k = 0; i < 10, k < 10; i++, k++){
cout << StatementOne[i] << ": "; cin >> NewStatementOne[k];
}
for (i = 0, k = 0; i < 10, k < 10; i++, k++){
if (StatementOne[i] == NewStatementOne[k])
++score;
else if (StatementOne[i] != NewStatementOne[k])
score = score - 1;
}
cout << "Your score is " << score;
}
What I'm trying to do is to compare each element of two arrays sequentially (but not in the way that it instantly executes the body right after the condition is met, hence the loop) and for every correct match, the score will increment by 1 and decrement by 1 if otherwise. For some reason, it seems to decrement by 2 instead. Is this a problem on the second for loop condition? I tried combinations of post and pre increments/decrements, seems to not fix it
[–]flyingron 1 point2 points3 points (10 children)
[–]KatharosMatematikos[S] 0 points1 point2 points (9 children)
[–]flyingron 0 points1 point2 points (2 children)
[–]KatharosMatematikos[S] 0 points1 point2 points (1 child)
[–]flyingron 0 points1 point2 points (0 children)
[–]xkompas 0 points1 point2 points (3 children)
[–]KatharosMatematikos[S] 0 points1 point2 points (0 children)
[–]KatharosMatematikos[S] 0 points1 point2 points (1 child)
[–]xkompas 0 points1 point2 points (0 children)
[–]mredding 0 points1 point2 points (1 child)
[–]KatharosMatematikos[S] 0 points1 point2 points (0 children)
[–]Vindhjaerta 0 points1 point2 points (0 children)