An index is always going to be an integer equal to or above 0.
If you have two integers, ex:
1 2 3
|
int x = 5;
float z;
z = x/2;
|
z is NOT going to be equal to 2.5. It will be equal to 2 because in C++, it will perform integer division by default.
Do this instead:
1 2 3
|
int x = 5;
float z;
z = x/2.0f;
|
This will not truncate the result.
Also, I can't see a reason to declare it like
1 2
|
int i;
for (i = 0; i < N; i++) {...;}
|
as opposed to
|
for (int i = 0; i < N; i++){...;}
|
in C++ (in C you would have to do declare variables beforehand).
In C++, declaring i inside of the for loop scope ensures that you don't accidentally try to access "i" outside of the loop itself.
If your edited code is still in the same section as your original, you are trying to access "i" after it already equals the value of index, so the values being calculated will be array[i/2], which in your case will always be array[50], whatever number that happens to be. Edit: In your case, this might work out to still give the correct answer, but this is bad practice and confusing for someone else to look at.
tl;dr:
So basically, you'd want to change the line to be
median = (array[50] + array[49])/2.0f;