Data types and structuresStoring numbers

Data is stored in a computer in different data types. Numbers are stored in integers or real numbers, text is stored in strings and pictures in graphical formats.

Part ofComputing ScienceSoftware design and development

Storing numbers

An integer is a whole number, a number without a decimal place. Integers can be positive or negative. Examples of integers are: 24, -36, 4303, -89730, 3, 7903493, 0.

The reference language shown below will declare a variable named ‘age’ as an integer. This program will only accept a whole number. Anything else will cause it to return an error.

DECLARE age AS INTEGER
SEND “Please enter your age” TO DISPLAY
RECEIVE age FROM (INTEGER) KEYBOARD
Displaying a user's age on a laptop screen.

When the number 45 is entered, the program works fine. However, here's the same program running with something different entered:

Coding behind the user's age.

Here the user entered the word 'old' when they were asked for their age. The program was expecting an integer (a whole number) and therefore it shows an error. If you want to store a whole number, then you need to use the data type known as an 'integer'.