← IGCSE Computer Science Paper 2

Type check

A validation check that tests an input is the expected data type, such as a whole number (INTEGER) for an age, and rejects letters or other wrong types.

Understanding Type check in IGCSE Computer Science Paper 2

What it does: The check tests the data type of Age and gives an error message if it is not an INTEGER, so letters are rejected. Being non-empty is a presence check. The type check rejects 'Ten' because it is a STRING. '4two' mixes digits and letters, so it is not an INTEGER. 42 is a whole number and passes.

Common mistakes: The program must read the age with INPUT Age so the value can be checked as an INTEGER. OUTPUT only displays a value and does not read one. An age is a whole number, so the type check expects INTEGER. Declaring Age as STRING would accept letters and break the arithmetic. It should be DECLARE Age : 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 47–57) and word search (Modules 47–70).

Take this worksheet further — free with Cloodit

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

Learning
Duo
A user types 'abc' into an age field that must be a whole number. Which check should reject it?
Type checkPresence check
Matches
Type check: Age must be between 0 and 120
↓
This describes a range check, not a type check. A type check tests the data type, for example that Age is an INTEGER.
Applying
Meanings
Term
type check
Meaning
A validation check that tests an input is the expected data type, such as a whole number (INTEGER) for an age, and rejects letters or other wrong types.
Practice
// Type check on Age
Testing
Gaps
DECLARE Age :
Check Answer
Spots
2OUTPUT "Enter your age"
3OUTPUT Age

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

The 'Abyssal Dragon' badge — Deep Sea Legend, 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. A user types 'abc' into an age field that must be a whole number. Which check should reject it?
A. Type check ✓
B. Presence check
A type check tests that the input is the expected data type. Letters are not a whole number, so they are rejected.
2. Which statement describes a type check correctly?
A. It checks the input is the expected data type, such as INTEGER ✓
B. It checks the input is typed in twice and matches
Typing the data twice is a double entry check (verification). A type check tests the data type.
3. A program expects the age 15. Which input would a type check for INTEGER reject?
A. 15
B. fifteen ✓
The word 'fifteen' is made of letters, so it is a STRING, not an INTEGER. A type check rejects it.
4. Which data type should an age field be checked against?
A. STRING
B. INTEGER ✓
An age is a whole number, so a type check tests for INTEGER. Letters would make it a STRING.
5. A type check on an age field accepts 200. Is this statement true or false?
A. True, a type check only tests the data type, and 200 is a whole number ✓
B. False, a type check always rejects numbers that are too big
Checking whether 200 is too large is a range check. A type check only tests that it is a whole number.

Match the Pairs

Age must be an INTEGER → A type check: the input must be a whole number, so letters like "ten" are rejected
Price must be a REAL number → A type check: the input must be a number that can have a decimal part, so text is rejected
A type check rejects letters when a whole number is expected, such as an age → IF Age is not an INTEGER THEN OUTPUT "Enter a whole number"
In the exam, a type check is described in words, linked to a data type → The input must be of type INTEGER
Type check: Age must be between 0 and 120 → This describes a range check, not a type check. A type check tests the data type, for example that Age is an INTEGER.
Age is stored as STRING so a type check will make sure it is a whole number → A STRING can hold letters, so it will not enforce whole numbers. The type check should require an INTEGER.

Key Term

type check
A validation check that tests an input is the expected data type, such as a whole number (INTEGER) for an age, and rejects letters or other wrong types.

Fill in the Blanks

1. // Type check: expects a whole number DECLARE Age : INTEGER
Hint: Type the data type keyword for whole numbers, which a type check on an age expects.
2. DECLARE Age : INTEGER DECLARE Name : STRING
Hint: Type the data type keyword for text made of letters.
3. DECLARE Age : INTEGER INPUT Age
Hint: Type the keyword that creates a variable with a chosen data type.
4. DECLARE Age : INTEGER OUTPUT "Enter your age" INPUT Age
Hint: Type the command that reads a value from the user into the variable.
5. // Type check: Age must be INTEGER DECLARE Age : INTEGER
Hint: Type the name of the variable whose data type is being checked.

Spot the Error

Question 1
A DECLARE Age : INTEGER
B OUTPUT "Enter your age"
C OUTPUT Age
D OUTPUT "Age accepted"
Line C — The program must read the age with INPUT Age so the value can be checked as an INTEGER. OUTPUT only displays a value and does not read one.
Question 2
A DECLARE Age : STRING
B INPUT Age
C OUTPUT Age + 1
Line A — An age is a whole number, so the type check expects INTEGER. Declaring Age as STRING would accept letters and break the arithmetic. It should be DECLARE Age : INTEGER.
Question 3
A // Type check: Age must be STRING
B DECLARE Age : INTEGER
C INPUT Age
Line A — A type check on an age tests that the input is a whole number (INTEGER). It does not expect STRING, so the comment should say INTEGER.
Question 4
A DECLARE Age : INTEGER
B DECLARE Name : STRING
C INPUT Name
D INPUT Age : INTEGER
Line D — The data type is set in the DECLARE statement, not in INPUT. The line should be just INPUT Age. The type check then compares the input with the declared INTEGER type.
Question 5
A DECLARE Age : INTEGER
B INPUT "Age"
C OUTPUT "Valid age: ", Age
Line B — Quotes make Age a piece of text, so the input would not be stored in the INTEGER variable. It should be INPUT Age with no quotes.

Student with a class code? Join your class →