Apologies if this has already been answered, but I couldn't find a good way to describe it or search it, which is why the title is a bit... odd.
int aGrade[4];
do {
printf("\nType the student %ds grade: ", (i + 1));
scanf("%d", &aGrade[i]);
i++;
} while (i <= 4);
For some reason, the last value input is always incremented by one. If, in the loop, aGrade[4]
's value is set to 5
, and I print its value to the console, it returns as 6
.
I have seen this happen with for
, do
and while
loops and I can't figure out what's happening. Thanks in advance! :)