Library routines inside your own subroutines
Your own subroutine can call a library routine such as ROUND, MOD, DIV or RANDOM in its statements and use the value it gives back, for example in a RETURN.
Understanding Library routines inside your own subroutines in IGCSE Computer Science Paper 2
What it does: RollDie calls RANDOM, which gives a number between 0 and 1. Multiplying by 5, rounding and adding 1 gives a whole number from 1 to 6, and RETURN sends it back. CalculateTotal is the programmer's own function and ROUND is a library routine. The value from the function call is passed into ROUND in the same statement. Number MOD 2 = 0 is either TRUE or FALSE, so the function returns a BOOLEAN even though MOD itself works on integers. ROUND takes the value to round first, then the number of decimal places. ROUND(Price, 2) rounds Price to 2 places.
Common mistakes: The keyword in a function header is RETURNS, not RETURN. The header should be FUNCTION Roll RETURNS INTEGER. A procedure does not return a value. The subroutine uses RETURN with ROUND, so it must be a FUNCTION.
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 429–438) and word search (Modules 419–438).
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
RETURN ROUND(Price, 2)Fill in the Blanks
Spot the Error
Student with a class code? Join your class →