Chapter 3. Usage of variables in Program

Well, we’ll do a simple program which asks two numbers, add them and then display the results as follows:

Text Box: Input the first number: 1
Input the second number: 5
The total is 5

 

 

 

 

Before write the program in computer, we’ll imagine a conversation between two people called John and James.

John: Hey, Tell me a number.

James: 4

John: Tell another number

James: 1

John: The total is 5. Am I correct?

James: Wow.. what a brilliant!

After James says 4, John needs to remember 4 in his memory before continue asking for the second number. And again John needs to remember 1 also somewhere in his memory. To calculate the sum of two numbers, John should add those two numbers which are in his short term memory, add them and give the total.

Now we’ll see how to write the program in computer to do the above.

First the computer will get the first number which inputs by the user and store it in a variable and store the second number in another variable. To calculate the sum, the computer reads the numbers which stores in two different variables, add them and display the result. So the variables are used in a program to store the values temporarily for computation and make the solution accurately.