Input Validation
In practice, program users don't always follow instructions, and you can get a mismatch between what a program expects as input and what it actually gets. Such conditions can cause a program to fail. However, often you can anticipate likely input errors, and, with some extra programming effort, have a program detect and work around them.
Suppose, for example, that you're writing a program that prompts the user to a non-negative integer. Another kind of error is to enter values that are not valid for the particular task the program is doing.
Suppose, for instance, that you had a loop that processes non-negative numbers. One kind of error the user can make is to enter a negative number. You can use a relational expression to test ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access