← IGCSE Computer Science Paper 2

Choosing between INTEGER and REAL

Use INTEGER for values that are always whole numbers, like a count of students. Use REAL if the value could have a decimal part, like a price or an average mark.

Understanding Choosing between INTEGER and REAL in IGCSE Computer Science Paper 2

What it does: Prices like 4.99 have a fractional part, so the variable must be declared as REAL. Seats are counted in whole units, so INTEGER is the suitable data type. A count of students is always a whole number. You cannot have 2.5 students, so INTEGER is the right choice. An average often comes out as a decimal, such as 72.5, even if every mark was whole. Use REAL. If the value could later need decimals, like a price changing to 5.50, choose REAL from the start. Choose by what the value could become, not just its current value.

Common mistakes: items is an INTEGER, so it can only hold whole numbers. 12.5 has a decimal part. The line should be items ← 12. A number of students is always a whole number, so it should be declared as INTEGER, not REAL.

Class: _____________________  ·  Name: _____________________  ·  Date: _________

Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.

This module's key terms are also in a printable crossword (Modules 327–336) and word search (Modules 317–336).

Take this worksheet further — free with Cloodit

Each concept is reinforced from every angle — learned, then applied, then tested.

Learning
Duo
Which data type should you use to store the number of students in a class?
REALINTEGER
Matches
DECLARE AverageMark : INTEGER AverageMark ← 72.5
↓
An average mark can have a decimal part, so it should be declared as REAL. INTEGER cannot store 72.5.
Applying
Meanings
Term
INTEGER or REAL
Meaning
Use INTEGER for values that are always whole numbers, like a count of students. Use REAL if the value could have a decimal part, like a price or an average mark.
Practice
DECLARE studentCount : INTEGER
Testing
Gaps
DECLARE NumStudents :
Check Answer
Spots
3price ← 4.50
4items ← 12.5

Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.

The 'Hermit Crab' badge — Definition Collector, one of Cloodit's 106 collectible badges
Students earn collectable badges

Over 100 of them, across seven natural biomes.

Study Buddy
Students build a real study resource

Turns their work into revision material ready for Flash Cards and Exam study.

Diamond Dash — one of Cloodit's live, competitive Sprint games
Students lock in with Sprints

Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.

A Cloodit certificate of achievement, ready to personalise and print
Custom printable certificates

Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.

Quick Questions

1. Which data type should you use to store the number of students in a class?
A. INTEGER ✓
B. REAL
A count of students is always a whole number. You cannot have 2.5 students, so INTEGER is the right choice.
2. Which data type should you use to store the price of a sandwich, such as 3.75?
A. REAL ✓
B. INTEGER
Prices can have a fractional part (pence or cents), so REAL is needed. INTEGER could not store 3.75.
3. Which data type suits a variable called AverageMark that holds the mean of several test marks?
A. INTEGER
B. REAL ✓
An average often comes out as a decimal, such as 72.5, even if every mark was whole. Use REAL.
4. Which declaration is the better choice for the number of books in a bag? A: DECLARE Books : INTEGER B: DECLARE Books : REAL
A. B: DECLARE Books : REAL
B. A: DECLARE Books : INTEGER ✓
You can only have a whole number of books, so INTEGER is the best fit.
5. True or false: a value that is whole today, such as a price of 5, should always be stored as INTEGER.
A. False ✓
B. True
If the value could later need decimals, like a price changing to 5.50, choose REAL from the start. Choose by what the value could become, not just its current value.

Match the Pairs

DECLARE NumStudents : INTEGER → Stores a count of students, which is always a whole number
DECLARE AverageMark : REAL → Stores an average mark, which might have a decimal part
A price can include pence or cents, so it needs a data type that allows decimals → DECLARE Price : REAL
A value that is always a whole number, such as the number of seats in a room, uses INTEGER → DECLARE NumSeats : INTEGER
DECLARE AverageMark : INTEGER AverageMark ← 72.5 → An average mark can have a decimal part, so it should be declared as REAL. INTEGER cannot store 72.5.
DECLARE NumStudents : REAL → A count of students is always a whole number, so INTEGER is the better choice. REAL is not needed here.

Key Term

INTEGER or REAL
Use INTEGER for values that are always whole numbers, like a count of students. Use REAL if the value could have a decimal part, like a price or an average mark.

Fill in the Blanks

1. DECLARE NumStudents : INTEGER
Hint: Type the data type for a count of students, which is always a whole number.
2. DECLARE Price : REAL
Hint: Type the data type for a price that can have pence or cents.
3. DECLARE AverageMark : REAL AverageMark ← 72.5
Hint: Type the data type that suits an average, which is often not a whole number.
4. DECLARE NumTickets : INTEGER NumTickets ← 4
Hint: Type the data type for a count of tickets, which can only be whole.
5. // Pocket money may include cents later DECLARE PocketMoney : REAL
Hint: The value is whole now but may need a decimal part later. Type the safer data type.

Spot the Error

Question 1
A DECLARE price : REAL
B DECLARE items : INTEGER
C price ← 4.50
D items ← 12.5
Line D — items is an INTEGER, so it can only hold whole numbers. 12.5 has a decimal part. The line should be items ← 12.
Question 2
A DECLARE avgMark : REAL
B DECLARE numStudents : REAL
C numStudents ← 30
D avgMark ← 67.5
Line B — A number of students is always a whole number, so it should be declared as INTEGER, not REAL.
Question 3
A DECLARE count : INTEGER
B count ← 12
C DECLARE price : INTEGER
D price ← 9.99
Line C — A price such as 9.99 has a decimal part, so price must be declared as REAL. An INTEGER cannot store it.
Question 4
A DECLARE total : INTEGER
B DECLARE average : INTEGER
C total ← 250
D average ← total / 4
Line B — An average can have a fractional part. 250 / 4 is 62.5, so average should be declared as REAL.
Question 5
A DECLARE temp : INTEGER
B temp ← 21.5
C OUTPUT temp
Line A — The temperature 21.5 has a decimal part, so temp must be REAL. INTEGER only holds whole numbers.

Student with a class code? Join your class →