previous | start | next

## Input Validation

- Input validation is an application of the if statement that verifies the user has given reasonable input.
- Example

  >     double area;
  >     cin >> area;

  user types "`five`" and hits return! (Causing `cin` to fail).
- After every input a good program will test:

  >     if (cin.fail())

- The actual input should also be validated, even if the type is correct.

  >     if (area < 0)

- Other strategies:

  -     if (cin)
           /* the stream did not fail */
        else
           /* the stream failed */

  - `if (cin >> x) ...`

previous | start | next