picasso: wrote in message to alt.comp.lang.learn.c-c++ > > Can anyone see any fault in this now that i should fix? Andrew Koenig replied: The program is much too large. Moreover, the problem is not well specified. Here's why I say so: When a problem specification uses the word "the," doing so often indicates a potential trouble spot. In this case, for example, you said you want to determine the biggest value in the input, and that use of "the" implicitly says that such a value exists! But what if there is no input? Then there is no biggest value. Similarly, if the input contains only one value, there is no second biggest value either. So the use of "the" in the problem specification has pointed out that there will be trouble unless there are two or more values in the input. This observation suggests a strategy that makes it unnecessary to use magic numbers such as -2147483648. For example, you might start by reading the first two elements of the input into the variables "biggest" and "secondbiggest." Then, if secondbiggest>biggest, swap their values. At this point, you have established an invariant: "biggest" contains the biggest value you've seen in the input so far. "secondbiggest" contains the second biggest value you've seen. with the proviso that the two variables might be equal if the first two input values are equal. Now, all you have to do is read the rest of the input, making sure to maintain the invariant each time you obtain a new input value. To see how to do it, let's call that value x. Now there are three cases: 1) x <= secondbiggest. In this case, biggest and secondbiggest are still the winners, so we don't need to do anything. 2) x > biggest. In this case, biggest is now the second biggest value you've seen and x is the biggest, so you have to adjust the variables accordingly: secondbiggest = biggest; biggest = x; 3) All other cases. Here, x <= biggest and x > secondbiggest, so there is a new second biggest value but the biggest value doesn't change. So each trip through the loop does the following: if (x > biggest) { secondbiggest = biggest; biggest = x; } else if (x > secondbiggest) { secondbiggest = x; } When you're done with the loop, biggest and secondbiggest will have the right values. No magic necessary. ---------------------- So although it works as is, this program needs some improvement.