How to drop highest and lowest scores

I am trying to create a function that asks the user to input 5 scores, drops the highest and lowest score, and then averages the 3 remaining scores. I am not sure how to get the function to drop the highest and lowest scores, can anyone help?
You can pass an array and use std::max_element and std::min_element.
http://www.cplusplus.com/reference/algorithm/max_element/
http://www.cplusplus.com/reference/algorithm/min_element/
That's the easiest way to do it, at least.
The other way u could use is sort the array into ascending order..
then remove the first and last entry from the list..
Sorting will generally be slower and incur a higher overhead, and you'd be calling stl algorithms for maximum efficiency anyway. In addition, sorting takes up memory space where as max/min is primarily comparison.
but for da beginner..they should understand the logic first..just use every single basic thing that they learn to accomplish their objective..
And why is sorting more logical than max/min? It causes modifications to memory, an overhead not necessary or incurred by a max/min algorithm, and thereby slowing down further. Unless you have such a specific situation that you need to program the code for the algs yourself, max/min is going to be easier, faster and less code than sorting, followed by taking it out, because that is NOT what the algs do.
Topic archived. No new replies allowed.