Distance Sensor. Calculating running median and Average
There are two main problems with your program. The first is noted in
Gerben's comment: you (attempt to) increment index (with a bad
syntax), while you should be incrementing i instead. The second
problem is these lines:



for (i = 0; i &lt;= 8; i++) {
    int_array[i] = 0;
}


Fix the index vs. i confusion, remove the lines above, and your
program should work.

Explanation: The first point should be obvious, I hope. I am
discussing here the second issue. At the end of the loop above, the
index i has the value 9. Later, in loop(), and assuming you fixed
the first issue, the program does

i++;
if (i == 9) {
    i = 0;
}


and i has the value 10. From there i will continue incrementing, and
you are always writing outside of the array.

The root of the problem is that you used the same variable i for two
different purposes. There are several solutions to this:


use different variable names for different purposes
use local variables whenever applicable (here: in setup())
be defensive in your tests: instead of if (i == 9) write
if (i &gt;= 9), but note that this alleviates but does not completely
solve the problem
remove the initialization of the array altogether.


I suggest removing the initialization because the array is a global
variable and, per the C++ standard, if not explicitly initialized it is
implicitly initialized to zero, so your initialization is redundant.