First, a design question: If the input is {2,4,2,3}, what is the output?
* Is it {2,2}, because they are indeed the two smallest inputs, or
* Is it {2,3}, because they are the two smallest unique values
Now, you have got new input. The options are:
0. Negative
1. It is a new record on smallness
2. It equals current minimum
3. It is between minimum and second
4. It equals second smallest
5. It is big
Case 1 must clearly update both current values.
Case 3 has to update the second.
There are numeric limit constants defined in standard library that are more expressive for the b and c to start with than those magic 99..9's.
Consider
1 2 3 4 5 6
|
while ( cin>>a ) {
if ( a < 0 ) { break; }
else if ( a < b )
{ ... }
else if ...
}
|
The >> can fail. This version protects from it.
A negative input breaks out from the loop and thus you don't need to test for it in the later cases.