← IGCSE Computer Science Paper 2

Writing a program with variables, constants, input and strings

A complete program declares variables and a CONSTANT, reads values with INPUT, processes them with assignments, then shows results with OUTPUT, using meaningful names and // comments.

Understanding Writing a program with variables, constants, input and strings in IGCSE Computer Science Paper 2

What it does: INPUT stores the value the user types in the variable HoursWorked, which must be declared first. An assignment with the ← operator stores the result of the arithmetic expression in the variable Wage. The variable being assigned goes on the left of ←, and the expression goes on the right. DIV gives the whole number of times 60 fits. MOD gives the remainder, which is the leftover seconds. MOD returns the remainder after division. For example, 135 MOD 60 is 15. In Cambridge pseudocode, the first character of a string is at position 1, not 0. Declare what you need, read values in, process them, then show the results.

Common mistakes: A constant is given its value with the assignment arrow, not =. It should be CONSTANT HourlyRate ← 12.5. WHOLE is not a Cambridge pseudocode data type. Whole numbers use INTEGER, so it should be DECLARE Seconds : INTEGER.

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 347–357) and word search (Modules 337–357).

Take this worksheet further — free with Cloodit

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

Learning
Duo
Which line correctly sets up a constant for a wage rate?
CONSTANT HourlyRate ← 12.50CONSTANT HourlyRate : REAL
Matches
CONSTANT HourlyRate ← HoursWorked * 2
↓
A constant must be given a literal value, not an expression that uses a variable. It should be written as CONSTANT HourlyRate ← 12.50.
Applying
Meanings
Term
DECLARE INPUT OUTPUT
Meaning
A complete program declares variables and a CONSTANT, reads values with INPUT, processes them with assignments, then shows results with OUTPUT, using meaningful names and // comments.
Practice
// Wage calculator
Testing
Gaps
HourlyRate ← 12.50
Check Answer
Spots
1DECLARE Hours : REAL
2CONSTANT HourlyRate = 12.5

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

The 'Parrotfish' badge — Function Builder, 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 line correctly sets up a constant for a wage rate?
A. CONSTANT HourlyRate ← 12.50 ✓
B. CONSTANT HourlyRate : REAL
A constant is given a literal value with ←. It is not declared with a data type like a variable.
2. Which line reads the hours worked from the user?
A. Hours ← INPUT
B. INPUT Hours ✓
INPUT is a command followed by the variable that will store the value.
3. Which line correctly calculates the wage?
A. Wage ← Hours * HourlyRate ✓
B. Hours * HourlyRate ← Wage
The variable being assigned goes on the left of ←, and the expression goes on the right.
4. Which expression gives the whole minutes in TotalSeconds?
A. TotalSeconds MOD 60
B. TotalSeconds DIV 60 ✓
DIV gives the whole number of times 60 fits. MOD gives the remainder, which is the leftover seconds.
5. Which expression gives the leftover seconds after removing whole minutes?
A. TotalSeconds MOD 60 ✓
B. TotalSeconds DIV 60
MOD returns the remainder after division. For example, 135 MOD 60 is 15.

Match the Pairs

CONSTANT HourlyRate ← 12.50 → Sets a fixed pay rate at the top of the wage program. The value is a literal and cannot change while the program runs.
Seconds ← TotalSeconds MOD 60 → Finds the seconds left over after taking out whole minutes from a total number of seconds.
Read the number of hours worked from the user into a declared variable → INPUT HoursWorked
Process the input by working out the wage from the hours and the constant rate → Wage ← HoursWorked * HourlyRate
CONSTANT HourlyRate ← HoursWorked * 2 → A constant must be given a literal value, not an expression that uses a variable. It should be written as CONSTANT HourlyRate ← 12.50.
Initial ← SUBSTRING(Name, 1, 3) → A length of 3 returns three characters, not a single initial. The length should be 1: SUBSTRING(Name, 1, 1).

Key Term

DECLARE INPUT OUTPUT
A complete program declares variables and a CONSTANT, reads values with INPUT, processes them with assignments, then shows results with OUTPUT, using meaningful names and // comments.

Fill in the Blanks

1. // Rate never changes CONSTANT HourlyRate ← 12.50
Hint: Type the keyword that declares a value which cannot change while the program runs.
2. DECLARE Hours : REAL INPUT Hours
Hint: Type the keyword that reads a value typed by the user into the variable.
3. // Calculate the wage Wage ← Hours * HourlyRate OUTPUT "Wage: ", Wage
Hint: Type the arithmetic operator that multiplies the hours by the rate.
4. Minutes ← TotalSeconds DIV 60 Seconds ← TotalSeconds MOD 60
Hint: Type the operator that gives the leftover seconds after whole minutes are removed.
5. DECLARE Name : STRING Initial ← SUBSTRING(Name, 1, 1) OUTPUT Initial
Hint: Type the string function that extracts part of a string, here the first character.

Spot the Error

Question 1
A DECLARE Hours : REAL
B CONSTANT HourlyRate = 12.5
C INPUT Hours
D OUTPUT Hours * HourlyRate
Line B — A constant is given its value with the assignment arrow, not =. It should be CONSTANT HourlyRate ← 12.5.
Question 2
A DECLARE Seconds : WHOLE
B DECLARE Mins : INTEGER
C INPUT Seconds
D Mins ← Seconds DIV 60
E OUTPUT "Minutes: ", Mins
Line A — WHOLE is not a Cambridge pseudocode data type. Whole numbers use INTEGER, so it should be DECLARE Seconds : INTEGER.
Question 3
A DECLARE Surname : STRING
B DECLARE Total : INTEGER
C READ Surname
D Total ← LENGTH(Surname)
E OUTPUT Total
Line C — Cambridge pseudocode reads a value from the user with INPUT, not READ. It should be INPUT Surname.
Question 4
A DECLARE Name : STRING
B DECLARE Shout : STRING
C INPUT Name
D Shout ← UPPER(Name)
E OUTPUT Shout
Line D — The Cambridge function that converts a string to upper case is UCASE, not UPPER. It should be Shout ← UCASE(Name).
Question 5
A DECLARE Total : INTEGER
B CONSTANT SecsPerMin ← 60
C # Read the total seconds
D INPUT Total
E OUTPUT Total DIV SecsPerMin
Line C — Comments in Cambridge pseudocode start with //, not #. It should be // Read the total seconds.

Student with a class code? Join your class →