Hi All,

I am currently learning C++ and I have been asked to make a program which will calculate the interest that would be paid on a deposit of a given size. One of the requirements is that we display an error message when non-integer data is entered.

There are a few approaches one can take.

Get input. Check the state of the input stream, if it's good, you got an integer. If it's bad, you didn't, so you need to clear the error state and flush out all that remains on the input stream and try again.

Other approach is to take all input as a string - that pretty much can't fail. Then parse the string to get the integer value it represents, if any. From that you'll know if it's good data or not.