📘 Paper 2 · Topic 10: Programming
10.1a Programming with Cambridge Pseudocode
Cambridge IGCSE Computer Science 0478 · ~16 min read · ✓ Free Lesson

Writing Complete Programs in Cambridge Pseudocode

In the IGCSE exam, Paper 2 requires you to write complete pseudocode programs — not just snippets. This lesson consolidates all the elements you have learned: variables, selection, iteration, arrays, procedures/functions, and file handling — combined into complete solutions.

Cambridge Pseudocode Quick Reference

ConceptPseudocode
Variable assignmentx ← 42
InputINPUT name
OutputOUTPUT "Hello " & name
Declare variableDECLARE count : INTEGER
IF statementIF x > 0 THEN...ELSE...ENDIF
CASE OFCASE OF x; 1: ...; OTHERWISE: ...; ENDCASE
FOR loopFOR i ← 1 TO 10; ...; NEXT i
WHILE loopWHILE cond DO; ...; ENDWHILE
REPEAT loopREPEAT; ...; UNTIL cond
Array declareDECLARE arr : ARRAY[1:10] OF INTEGER
Array accessarr[i]
ProcedurePROCEDURE name(p:TYPE); ...; ENDPROCEDURE; CALL name(arg)
FunctionFUNCTION name(p:TYPE) RETURNS TYPE; ...; RETURN val; ENDFUNCTION; x ← name(arg)
File readOPENFILE "f" FOR READ; READFILE "f", v; CLOSEFILE "f"
File writeOPENFILE "f" FOR WRITE; WRITEFILE "f", data; CLOSEFILE "f"
String lengthLENGTH(s)
SubstringSUBSTRING(s, start, length)
Arithmetic+, -, *, /, DIV (integer div), MOD (remainder)
Comparison=, <>, <, >, <=, >=
BooleanAND, OR, NOT

Complete Program Example 1: Grade Calculator

// Reads 5 exam scores and outputs grades
DECLARE scores : ARRAY[1:5] OF INTEGER
DECLARE i : INTEGER
DECLARE total : INTEGER
total ← 0
FOR i ← 1 TO 5
    INPUT scores[i]
    total ← total + scores[i]
NEXT i
average ← total / 5
IF average >= 70 THEN
    OUTPUT "Grade A"
ELSE IF average >= 60 THEN
    OUTPUT "Grade B"
ELSE IF average >= 50 THEN
    OUTPUT "Grade C"
ELSE
    OUTPUT "Fail"
ENDIF
OUTPUT "Average: " & average

Complete Program Example 2: Number guessing validation

// Validates a number between 1 and 100
DECLARE guess : INTEGER
REPEAT
    OUTPUT "Enter a number between 1 and 100:"
    INPUT guess
UNTIL guess >= 1 AND guess <= 100
OUTPUT "Valid guess: " & guess

Complete Program Example 3: File reading with count

// Counts records in a file
DECLARE line : STRING
DECLARE count : INTEGER
count ← 0
OPENFILE "data.txt" FOR READ
WHILE NOT EOF("data.txt") DO
    READFILE "data.txt", line
    count ← count + 1
ENDWHILE
CLOSEFILE "data.txt"
OUTPUT "Total records: " & count

Trace Table for Example 2

Iterationguess (INPUT)guess >= 1 AND guess <= 100Loop continues?
1150FALSEYes (repeat)
2-5FALSEYes (repeat)
342TRUENo (exit)
Exam tip: In Paper 2, exam questions often give you part of a program and ask you to complete it, or give you a description and ask you to write the whole program. Always declare variables before using them, always close files, always match ENDIF/ENDWHILE/NEXT/ENDCASE/ENDPROCEDURE/ENDFUNCTION with their opening keywords.
⚠️ Common Mistakes in Full Programs
  • Forgetting to initialise variables (e.g., total ← 0 before a summing loop)
  • Not declaring arrays before use
  • Mismatched closing keywords — every IF needs ENDIF, every WHILE needs ENDWHILE
  • Using = instead of ← for assignment (← assigns; = compares)
  • Using + to join strings — use & for concatenation
Video coming soon
Click slide or press arrow keys to navigate
✍️

Worksheet — Full Programs

3 questions · 12 marks

Q1Write a complete pseudocode program that asks the user for 3 numbers and outputs the largest. [4]
✅ Mark scheme
DECLARE a, b, c : INTEGER; INPUT a, b, c (or separate INPUTs) [1]; largest ← a; IF b > largest THEN largest ← b ENDIF [1]; IF c > largest THEN largest ← c ENDIF [1]; OUTPUT largest [1]. Award marks for correct logic even if exact syntax slightly varies.
Q2Write pseudocode to store the numbers 1-10 in an array, then output only the even numbers. [4]
✅ Mark scheme
DECLARE nums : ARRAY[1:10] OF INTEGER [1]; FOR i ← 1 TO 10; nums[i] ← i; NEXT i [1]; FOR i ← 1 TO 10; IF nums[i] MOD 2 = 0 THEN [1]; OUTPUT nums[i] ENDIF; NEXT i [1]
Q3Write a trace table for this pseudocode. x ← 10; y ← 3; WHILE x > y DO; x ← x - y; ENDWHILE; OUTPUT x. [4]
✅ Mark scheme
x=10, y=3, 10>3=T, x←7 [1]; x=7, y=3, 7>3=T, x←4 [1]; x=4, y=3, 4>3=T, x←1 [1]; x=1, y=3, 1>3=F — loop exits. OUTPUT 1 [1]
Quiz — Full Programs
Q 1 of 7
Score
/ 7
Click to reveal
TermDefinition
🎯

Mini Test — Full Programs

10 minutes · mixed marks

← 9.2 Logic Expressions Topic 10: Programming Next: 10.1b Subroutines →