Input streams, such as cin, can go into an error state where no further input will be processed. This might happen in the code provided by whiteflags if non-numeric input was entered at the prompt. Since omgnumbers is of type double - which incidentally refers to double precision floating-point values - then entering something like "foobar" at the prompt would cause trouble where a program might be expecting something more along the lines of "123.456" as an example.

The while loop is designed to repeatedly test the state of the cin stream thus ensuring that only valid double values can be entered. The cin.good call returns whether or not the stream is in a good state. If the stream is in a good state, then a valid double value must have been entered and we can skip the rest of the loop body. However, if the stream is in a bad state then we need to deal with the consequences of this. If the stream is in a bad state then the user tried to enter something non-numeric at the prompt and the bad input must be dealt with.

The first thing the loop body does is clear the bad/error state with a call to cin.clear. Without this, most operations using the stream will not function properly or at all. The next step the loop body does is to get rid of all the bad data currently in the stream by calling cin.ignore. If this was not done, then the bad data that caused the problem in the first place would remain in the input buffer and the subsequent attempt at extracting another double value from the stream would simply cause the cin stream to go into a bad state all over again and we'd wind up in a never ending loop. The remaining lines of the loop body re-prompt the user for data and attempt to extract data.

There are other ways of writing that loop, one might be to test the extraction operation itself to see if it succeeded or not. This would eliminate a couple lines of code:
Code:
cout << "enter anything: ";
while ( !(cin >> omgnumbers) )
{
   cin.clear();
   cin.ignore(numeric_limits<streamsize>::max(), '\n');
   cout << "enter anything (choose a number to stop): ";
}
The basics still remain however... clear the error state followed by removing the bad data from the stream so we can re-prompt and attempt to process some good data.