Needing a little bit of help with finding the minimum value

This is a discussion on Needing a little bit of help with finding the minimum value within the C++ Programming forums, part of the General Programming Boards category; For one of my intro to C++ assignments, I must write code where a group of athletes performances is judged ...

Needing a little bit of help with finding the minimum value

For one of my intro to C++ assignments, I must write code where a group of athletes performances is judged by a variable number of judges. The performance score of the athletes is obtained by rejecting both the lowest and the highest score, and taking the average of the remaining scores. I have most of it figured out I think, however the minimum score is a bit over my head; the max score can be reset to 0, for following athletes to be judged, but the minimum cannot, because no score will be less than 0 to be picked up as a low score. My code:

My min variable works the first time around, and I did not have to compare it to 0. However, when the loop comes back around again to judge the next athlete, the min integer is still holding a value from a previous judged athlete. My problem is resetting min for the next loop. Resetting it to 0 won't help like it would for total, and max, because it does the exact opposite.

Describe your thought process in answering MWAAAHAAA's question of picking the smallest number among 6, 8, 2, 9, 1, 9, 6. In fact, you should do this away from your computer, without any thought of programming. Select some cards from a deck of cards, if you will, and go through the exercise physically, taking care to be very methodical, considering one card at a time.

I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.

Okay. 6 is less than 8. 6 is not less than 2, thus 2 is the newest low number. 2 is less than 9. 2 is not lower than 1, thus 1 is the newest low number. 1 is less than 9. 1 is less than 6.

Now lets say I have a new deck of cards, where my mind is supposed to keep a clean slate in terms of the lowest number. But I can't shake it off. Now, the deck of cards is 4, 2, 6, 7, 10, 3. I won't be able to pick a low number from these because I can't shake off the 1 as the lowest number from my last batch of cards. Thus, I accidentally pick 1 as the lowest number, even if it wasn't part of this new batch of cards.

I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.

Because 0 was never part of the batch to begin with. I always knew that, that's why I knew it wouldn't work to be reset to that. 0 would always be the lowest number. I just brought 0 up because that's how it works to reset integers max, and total. I'm still trying to understand what you're getting at.

I'm not trying to annoy you, the solution you managed to find actually works, although it is not really robust. I am just trying to get you to figure out the alternative for yourself. And to be completely fair with you, you'd have to actually rewrite your algorithm slightly (or more to the point, you'd have to include an additional step right in the middle) in order to be able to do what I (and I imagine laserlight as well) had in mind. I imagine you are simply to locked on your current solution, to consider the alternative.

So, get your mind off the problem, do something else, and if you're interested enough in it, you may figure it out tomorrow. I'd hate to simply spell the solution out for you