medians and vectors
Any ideas on how to do this?
Write a program that allows the user to enter
a set of positive integers in order from smallest to largest and then
the program will output the median of the set of numbers. The user
will type a -5 to indicate that the list of integers is complete. (The -5
is not part of the list).
If the user doesn't enter the numbers in order, the program should
display "Numbers entered out of order. Exiting." and exit. You can exit the
program using the command: exit(1)
Write this program using vectors.
My problem is that I can't seem to figure out in my head how to run a loop for this.
Hint: use the push_back() member function of vector.
And for the order part (numbers are to be entered in order from smallest to largest) when doing the push_back just check the last valid element in the vector, if the last element is larger than the current number you are about to "push" then the user is entering the value out of order.