Input Validation

Programmers need to make sure that the data they allow into their programs is sensible. They can use input validation to check that the data is within a range.

For example if we wanted a program that only allowed an age of between 0 and 120 years then we could use a IF statement to check.

validation2

However, this would only give the user two chances to get it right before the program continued anyway.

By changing the if to a while, the program will continue to ask the user for the age until it falls within the range.

validation

This is an example of input validation and is one of the standard algorithms you should know.

Leave a Reply

Your email address will not be published. Required fields are marked *