Page 13 - Touchcode_C7_Flipbook
P. 13
HOW DO WE VALIDATE USER INPUT IN PROGRAMMING?
Data validation is the process of ensuring that the data entered by the user is valid. Consider
an example, if someone asks you, “What did you have today for lunch?” You are supposed
to answer the person what food item you had for lunch. Suppose you answer “I have a red
box in my hand”. This is not an acceptable answer to the question which was asked.
In the same way, in programming, when you create a variable with a specific data type,
and the user is supposed to enter a certain value in that data type, you should make sure
that the user enters the right type of value, which did not cause any error during program
execution. This validation of Input plays a vital role while writing a program.
For validating the input entered by the user, the most common practice is to set a flag which
shows the value as ‘true’ and ‘false’. The default value of flag is ‘false’.
If the value entered by the user matches with the expected value, the flag will be reset
to ‘true’ and the program is executed.
If the value entered by the user does not matches with the expected value, the flag will
be reset to ‘false’ and an error message is shown.
Coding fact
Elon Musk is the CEO of Tesla Motors and SpaceX, two of the most influential
tech industries of the current times. He was also an inspiration for the Iron Man.
MATH OPERATIONS IN PROGRAMMING
Variable is a name given to a storage area which defines the size, layout, range set of
operations to be performed on the variable.
Once you declare the data types, you will learn to perform the operations on the data types.
Operator: It is a symbol which operates on a value assigned to a variable. Example: +,-,
*, \.
Operand: It is a value on which the operator performed an operation.
Arithmetic operations
Arithmetic operation uses arithmetic operators to combines two or more numeric
expressions. The arithmetic operators perform operations such as: addition, subtraction,
multiplication, division, and modulus. In the table given below, we are taking the value of
variable a=10, and b=30.
Variables in Real Life 11

