I'm trying to find the median in an array and am stuck at the end of my code, obviously grade[median] isn't showing me the grade in the median location, like i'm trying to do. of course, it gives me an error. So what would be the proper way to make it show me the median location in the array? Also, this will only work correct with an odd number of array elements and I know to find the median in an array of even amount of elements, you take the 2 middle terms then divide by 2. Any help on getting the location for the 2 middle terms and dividing by 2?

ps- I know it needs to be sorted first but that is being taken care of by a different person. My job is to come up with the algorithm for finding the median.

Code:int grade[25]; int i = 0; float median; do { cout << "Enter grades, to quit enter 999\n"; cin >> grade[i]; i++; } while(grade[i-1] != 999); i = i-1; for (int j=0; j<i; j++) { cout << grade[j] << endl; } median = (i+1) / 2; cout << grade[median] << endl;