Handling Any Number of Prizes

One of the primary advantages of the method we've used so far to find the heaviest pumpkin(s) is that we didn't have to save the weights of all the pumpkins as we went along. If we don't mind saving all the weights, then we can solve the “three prize” problem in a different way. Let's assume for the purpose of simplicity that there are only five weights to be saved, in which case the solution looks like this:

Read in all of the weights.
Make a list consisting of the three highest weights in descending order.
Award the first, second, and third prizes, in that order, to the three entries in the list of highest weights.

Now let's break those down into substeps that can be more easily translated into C++:

Get C++: A Dialog Programming with the C++ Standard Library now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.