This program is suppose to calculate the median from a file containing 14 integers separated by spaces. The program doesn't work, it output a negative number as a median. please help.
If count is 14 count%2 == 0 is false so the the else part in calc_median will run: median = numbers[location + 1]; Problem here is that location is still zero and you have not written anything to the array so it will only contain garbage values, possibly negative.
vin, you are right. But if the count variable is wrong it is still the same problem. looping until .eof() often do one iteration too much. Try replace the do-while loop in read_file with: