← IGCSE Computer Science Paper 2

Choosing a variable or a constant

Use CONSTANT for a value fixed while the program runs, e.g. VAT rate or pi. Use a variable (DECLARE) for a value that changes or is input, e.g. score or answer.

Understanding Choosing a variable or a constant in IGCSE Computer Science Paper 2

What it does: A value that stays the same throughout the program is declared with CONSTANT, as Pi is here. The VAT rate is fixed for the whole run of the program, so it should be a constant. Being a REAL number does not decide it. Pi never changes, so use a constant. A value entered by the user is not known in advance and can differ each time, so use a variable. Constants hold fixed values. Values that are input belong in variables. Lives left changes during play. The days in a week is fixed, so it suits a constant. DECLARE creates a variable, which is the right choice when the value changes during the program.

Common mistakes: Price is entered by the user, so its value changes. It must be a variable, DECLARE Price : REAL, not a CONSTANT. The VAT rate is fixed while the program runs, so it should be a constant: CONSTANT VATRate ← 0.2.

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 317–326) 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 should store the VAT rate of 0.2 that never changes while the program runs?
A variable: DECLARE VATRate : REALA constant: CONSTANT VATRate ← 0.2
Matches
DECLARE VATRate : REAL VATRate ← 0.2
↓
The VAT rate is fixed for the whole program, so it should be a constant (CONSTANT VATRate ← 0.2), not a variable that could be changed.
Applying
Meanings
Term
CONSTANT
Meaning
Use CONSTANT for a value fixed while the program runs, e.g. VAT rate or pi. Use a variable (DECLARE) for a value that changes or is input, e.g. score or answer.
Practice
CONSTANT VatRate ← 0.2
Testing
Gaps
VATRate ← 0.2
Check Answer
Spots
1CONSTANT VATRate ← 0.2
2CONSTANT Price ← 0.0

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

The 'Gila Monster' badge — Patient Coder, 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 should store the VAT rate of 0.2 that never changes while the program runs?
A. A variable: DECLARE VATRate : REAL
B. A constant: CONSTANT VATRate ← 0.2 ✓
The VAT rate is fixed for the whole run of the program, so it should be a constant.
2. Which should store pi (3.14159) used to calculate the area of circles?
A. A constant, because pi never changes ✓
B. A variable, because it is a REAL number
Being a REAL number does not decide it. Pi never changes, so use a constant.
3. A quiz program adds 1 to the player's score after each right answer. What should score be?
A. A constant, because it starts at 0
B. A variable, because its value changes ✓
Score changes while the program runs, so it must be a variable declared with DECLARE.
4. The user types their answer to a question using INPUT. What should store it?
A. A variable: DECLARE Answer : STRING ✓
B. A constant: CONSTANT Answer ← ""
A value entered by the user is not known in advance and can differ each time, so use a variable.
5. Which statement is a correct reason for using a constant?
A. The value is fixed while the program runs ✓
B. The value will be typed in by the user
Constants hold fixed values. Values that are input belong in variables.

Match the Pairs

CONSTANT VATRate ← 0.2 → A fixed value that is set once and never changes while the program runs
DECLARE Score : INTEGER → A variable for a value that can change as the program runs, such as a player's score
Pi never changes while the program runs, so store it as a constant → CONSTANT Pi ← 3.142
The user's answer is typed in and can be different each time, so store it in a variable → DECLARE Answer : STRING INPUT Answer
DECLARE VATRate : REAL VATRate ← 0.2 → The VAT rate is fixed for the whole program, so it should be a constant (CONSTANT VATRate ← 0.2), not a variable that could be changed.
CONSTANT Score ← 0 Score ← Score + 10 → A score changes as the program runs, so it must be a variable (DECLARE Score : INTEGER), because a constant cannot be updated.

Key Term

CONSTANT
Use CONSTANT for a value fixed while the program runs, e.g. VAT rate or pi. Use a variable (DECLARE) for a value that changes or is input, e.g. score or answer.

Fill in the Blanks

1. CONSTANT VATRate ← 0.2
Hint: Type the keyword used to declare a value that stays fixed while the program runs, such as a tax rate.
2. DECLARE Score : INTEGER
Hint: Type the keyword used to declare a variable whose value changes as the program runs.
3. CONSTANT Pi ← 3.14
Hint: Type a suitable identifier for the fixed circle ratio.
4. DECLARE Answer : STRING INPUT Answer
Hint: Type the variable that stores the value the user enters.
5. CONSTANT VATRate ← 0.2 Total ← Price * (1 + VATRate)
Hint: Type the name of the fixed value that is used in the calculation.

Spot the Error

Question 1
A CONSTANT VATRate ← 0.2
B CONSTANT Price ← 0.0
C INPUT Price
D OUTPUT Price * (1 + VATRate)
Line B — Price is entered by the user, so its value changes. It must be a variable, DECLARE Price : REAL, not a CONSTANT.
Question 2
A DECLARE Price : REAL
B DECLARE VATRate : REAL
C INPUT Price
D OUTPUT Price * (1 + VATRate)
Line B — The VAT rate is fixed while the program runs, so it should be a constant: CONSTANT VATRate ← 0.2.
Question 3
A CONSTANT MaxLives ← 3
B DECLARE Lives : INTEGER
C MaxLives ← Lives
D Lives ← Lives - 1
Line C — MaxLives is a constant and cannot be assigned a new value. The changing value must go into the variable: Lives ← MaxLives.
Question 4
A DECLARE Answer : STRING
B CONSTANT Answer ← "yes"
C OUTPUT "You typed ", Answer
Line B — The answer is typed in by the user and changes each time. It needs a variable and INPUT Answer, not a CONSTANT with a fixed value.
Question 5
A DECLARE Score : INTEGER
B Score ← 0
C CONSTANT Score ← Score + 1
D OUTPUT Score
Line C — A score changes as the program runs, so it is a variable. It is updated with an assignment: Score ← Score + 1. CONSTANT cannot be used.

Student with a class code? Join your class →