Input values should always be checked for what?
Input values should always be checked for the following
- Appropriate range
- Division by zero
- If division is taking place
In C++ there is a different range for different types of data types. These ranges define the maximum and minimum value that data type can hold. For example, int has range of -2,147,483,648 to 2,147,483,647 and char has range of -128 to 127 by default and Bool has range of true or false, etc.
Reasonableness is the check if the data is reasonable or not. For example, if data does not match what we expect from a last name field then the data is not reasonable.
Division by zero is undefined. Since division by zero is undefined in mathematics and computer science has a lot of concepts of maths, that is why division by zero is also undefined in computer science.
If division is taking place
You have to make sure if in your statement division is taking place as expected. I know it seems stupid but it can make you scratch your head. C++ is more about data types and more critical language. You have to do whatever you want to do by yourself.
For example, if you divide three by five like this ⅗ then you will end up getting an error. You have to do it like this 3.0/5
Hope this will help.