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:

1.
Read in all of the weights.
2.
Make a list consisting of the three highest weights in descending order.
3.
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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.