Computer programs use data types to organise different types of data in a program. Data can also be constant or variable within programs and functions.
The main purpose of computer programs is to collect and process data. A computer can change what it does depending on the data that it has to work with.
The data that is used in a program is referred to as the data values. These influence the sequence of instructions and the program outputs.
The data values collected and used by a program control:
Data values can be input by a user or obtained from a range of different sources:
Even mouse movements and button clicks are input data, and the location and timing of them can affect what happens.
Algorithms have data values that can be fixed or variable.
The following algorithms each use data values. Can you work out which of these is using fixed values and which is using variable values?
Algorithm A
Add 4 to 5
Print the resultAlgorithm B
Ask the user to type in a whole number
Add 5 to that number
Print the resultAlgorithm C
If 4 is less than 5
Add 5 to 4
Print the result
Otherwise
Print "no"Algorithm D
Ask the user to type in a whole number
If the number typed in is less than 5
Add 5 to the number typed in
Print the result
Otherwise
Print "no"Algorithms A and C are using fixed values (4 and 5). There is no option within the algorithm to alter the data. These algorithms will always produce the same results.
Algorithms B and D are using variable data. The data input depends on the choice of the user. The algorithm will output a different result dependent on the user input.