← IGCSE Computer Science Paper 2

Assigned value must match the variable's data type

An error when a value assigned to a variable has a different data type from the one it was declared with, such as storing a name in an INTEGER variable.

Understanding Assigned value must match the variable's data type in IGCSE Computer Science Paper 2

What it does: STRING values are written in double quotes, so "Ali" matches the STRING variable Name. Age was declared as INTEGER, so it can only hold whole numbers. "Ali" is a STRING, which causes a type mismatch. 42 is an INTEGER literal and the variable is declared as INTEGER, so the types match. A CHAR holds exactly one character in single quotes. "Ali" is a STRING, so the types do not match.

Common mistakes: Age was declared as INTEGER, so it can only hold whole numbers. The text "Ali" is a STRING, which causes a type mismatch. It should be a whole number such as Age ← Age + 1. Name is assigned the text "Ali", so it must be declared as STRING. An INTEGER variable cannot hold text. It should be DECLARE Name : STRING.

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
DECLARE Age : INTEGER Age ← "Ali"
Valid: Age can hold any value you assign to itType mismatch: a STRING cannot be stored in an INTEGER variable
Matches
DECLARE Score : INTEGER Score ← "Ali"
↓
Type mismatch: text is assigned to an INTEGER variable. Score should be given a whole number such as 45.
Applying
Meanings
Term
type mismatch
Meaning
An error when a value assigned to a variable has a different data type from the one it was declared with, such as storing a name in an INTEGER variable.
Practice
DECLARE Age : INTEGER
Testing
Gaps
DECLARE Age :
Check Answer
Spots
2Age ← 15
3Age ← "Ali"

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

The 'Narwhal' badge — Unicorn 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. DECLARE Age : INTEGER Age ← "Ali"
A. Valid: Age can hold any value you assign to it
B. Type mismatch: a STRING cannot be stored in an INTEGER variable ✓
Age was declared as INTEGER, so it can only hold whole numbers. "Ali" is a STRING, which causes a type mismatch.
2. Which assignment is correct for DECLARE Name : STRING?
A. Name ← Ali
B. Name ← "Ali" ✓
STRING literals must be written inside double quotes. Without quotes, Ali looks like an identifier, not text.
3. Which assignment is correct for DECLARE Grade : CHAR?
A. Grade ← 'A' ✓
B. Grade ← "A"
In Cambridge pseudocode a CHAR literal uses single quotes. Double quotes mark a STRING.
4. DECLARE Score : INTEGER Score ← 42 Is this assignment valid?
A. Yes: 42 is a whole number, so it matches INTEGER ✓
B. No: numbers cannot be stored in variables
42 is an INTEGER literal and the variable is declared as INTEGER, so the types match.
5. DECLARE Initial : CHAR Initial ← "Ali" What is the problem?
A. A STRING of several characters is assigned to a CHAR variable ✓
B. The variable name Initial is not allowed
A CHAR holds exactly one character in single quotes. "Ali" is a STRING, so the types do not match.

Match the Pairs

DECLARE Age : INTEGER Age ← "Ali" → A type mismatch: the text "Ali" cannot be stored in an INTEGER variable
DECLARE Grade : CHAR Grade ← 'B' → A correct assignment: a single character in single quotes matches the CHAR type
A STRING variable must be given text inside double quotes → DECLARE Name : STRING Name ← "Ali"
A CHAR variable must be given a single character inside single quotes → DECLARE Initial : CHAR Initial ← 'A'
DECLARE Score : INTEGER Score ← "Ali" → Type mismatch: text is assigned to an INTEGER variable. Score should be given a whole number such as 45.
DECLARE Letter : CHAR Letter ← "A" → A CHAR value needs single quotes, not double quotes. It should be Letter ← 'A'.

Key Term

type mismatch
An error when a value assigned to a variable has a different data type from the one it was declared with, such as storing a name in an INTEGER variable.

Fill in the Blanks

1. DECLARE Age : INTEGER Age ← 15
Hint: Type the data type that matches the whole number 15 being assigned.
2. DECLARE Name : STRING Name ← "Ali"
Hint: Type the data type that matches text written in double quotes.
3. DECLARE Grade : CHAR Grade ← 'A'
Hint: Type the data type that matches a single character in single quotes.
4. DECLARE Town : STRING Town ← "Leeds"
Hint: Type the assignment operator that stores a value in the variable.
5. DECLARE Initial : CHAR Initial ← 'K'
Hint: Type the keyword that creates a variable with a fixed data type.

Spot the Error

Question 1
A DECLARE Age : INTEGER
B Age ← 15
C Age ← "Ali"
D OUTPUT Age
Line C — Age was declared as INTEGER, so it can only hold whole numbers. The text "Ali" is a STRING, which causes a type mismatch. It should be a whole number such as Age ← Age + 1.
Question 2
A DECLARE Name : INTEGER
B Name ← "Ali"
C OUTPUT Name
Line A — Name is assigned the text "Ali", so it must be declared as STRING. An INTEGER variable cannot hold text. It should be DECLARE Name : STRING.
Question 3
A DECLARE Grade : BOOLEAN
B Grade ← 'B'
C OUTPUT Grade
Line A — Grade stores the single character 'B', so it must be declared as CHAR. A BOOLEAN variable can only hold TRUE or FALSE. It should be DECLARE Grade : CHAR.
Question 4
A DECLARE City : STRING
B DECLARE Age : INTEGER
C City ← Leeds
D Age ← 14
Line C — A STRING value needs double quotes. Without them, Leeds looks like a variable name, not text. It should be City ← "Leeds".
Question 5
A DECLARE Initial : CHAR
B DECLARE Name : STRING
C Initial ← "A"
D Name ← "Ali"
Line C — A CHAR value must be written in single quotes. Double quotes make it a STRING literal, which is a type mismatch. It should be Initial ← 'A'.

Student with a class code? Join your class →