Because you are outputing values just after the last read everytime.
while(infile >> myArray[index++]) will read number into myArray[index] and increase index afterward. (e.g. read value into myArray[3] and increase index to 4)
Then you are trying to read tan one-past the end value.
If i change the while loop and make it index instead of index++ it outputs all the values correctly. Howcome, since I did not increment the index anywhere?
If I had 5 values from 1 to 5 in a column in a text file. How would I square all values and add them which equals 55 and then divide by the total number of values being 5. Therefore the answer would be 11.