Matching the variable's data type to the file data
The variable used with READFILE or WRITEFILE needs a data type that suits the data: STRING for a line of text, INTEGER for a whole number. A wrong type causes errors.
Understanding Matching the variable's data type to the file data in IGCSE Computer Science Paper 2
What it does: The variable is declared as STRING first, so it matches the text that READFILE reads. Total is declared as INTEGER, which suits the whole number that WRITEFILE stores. The data type must suit the data being read, otherwise errors can occur. "Hello class" is text, so STRING is needed. An INTEGER can only store whole numbers. The type is chosen in the DECLARE statement, before the variable is used with the file.
Common mistakes: Total is an INTEGER read from the file, so you can only add a whole number to it. "10" is a string. It should be Total ← Total + 10. Score is declared as INTEGER, so it must hold a whole number. A string cannot be stored in it. It should be Score ← 85.
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 489–499) and word search (Modules 479–499).
Take this worksheet further — free with Cloodit
Each concept is reinforced from every angle — learned, then applied, then tested.
Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.
Over 100 of them, across seven natural biomes.
Turns their work into revision material ready for Flash Cards and Exam study.
Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.
Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.
Quick Questions
Match the Pairs
Key Term
DECLARE LineOfText : STRINGFill in the Blanks
Spot the Error
Student with a class code? Join your class →