0% found this document useful (0 votes)
173 views25 pages

Mastering Pseudocode for IGCSE 0478

This document serves as a comprehensive revision guide for mastering pseudocode in Cambridge IGCSE Computer Science (0478). It covers the fundamentals of pseudocode, including data types, variables, operators, control structures, loops, arrays, and procedures/functions, emphasizing the importance of logical problem-solving over syntax. The guide also provides examples and best practices for writing pseudocode effectively.

Uploaded by

shaikhasheem64
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
173 views25 pages

Mastering Pseudocode for IGCSE 0478

This document serves as a comprehensive revision guide for mastering pseudocode in Cambridge IGCSE Computer Science (0478). It covers the fundamentals of pseudocode, including data types, variables, operators, control structures, loops, arrays, and procedures/functions, emphasizing the importance of logical problem-solving over syntax. The guide also provides examples and best practices for writing pseudocode effectively.

Uploaded by

shaikhasheem64
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

IGCSE Computer Science 0478: Complete

Pseudocode Revision Guide (Chapter 7)


Introduction
This comprehensive revision document covers everything you need to master pseudocode
for Cambridge IGCSE Computer Science (0478) Paper 2. Chapter 7 introduces algorithm
design and pseudocode as the fundamental language for problem-solving—independent of
any specific programming language[1].
Pseudocode bridges the gap between human logic and computer code. Unlike Python or
Java, pseudocode is universal and Cambridge uses it in exams to test logic, not syntax. This
means your understanding of how to solve problems matters more than perfect keyword
formatting[1][2].

Part 1: Pseudocode Fundamentals


1.1 What is Pseudocode?
Pseudocode is a plain-language description of an algorithm that:
Uses structural conventions similar to programming languages
Is intended for human reading (not machine reading)
Omits details essential for machine understanding (like exact syntax)
Focuses on logical steps to solve a problem[2]
Key principle: Pseudocode is language-agnostic. You write the same pseudocode structure
whether you later implement it in Python, Java, C++, or any language.

1.2 Why Learn Pseudocode for IGCSE?


Universal standard: Teaches problem-solving without language-specific syntax bias
Exam focus: Examiners reward logic and structure, not syntax
Foundation for A-Levels: Preparation for Cambridge A-Level Computer Science
Industry relevance: Used by developers worldwide for algorithm design before
coding

Part 2: Data Types and Variables


2.1 Primitive Data Types
Cambridge IGCSE recognizes five primitive data types in pseudocode[3]:
Data Type Description Examples
INTEGER Whole numbers (positive, negative, zero) -50, 0, 42, 999
REAL Decimal numbers (floating-point) -3.14, 0.5, 2.718
STRING Sequence of characters enclosed in quotes "Hello", "A", ""
CHAR Single character 'A', '5', '*'
BOOLEAN Logical values TRUE, FALSE

Table 1: Primitive Data Types in Cambridge Pseudocode


String note: A string can contain zero or more characters. The empty string "" is valid.

2.2 Declaring Variables and Constants


Variables: Storage locations whose values can change during algorithm execution.

DECLARE VariableName AS DataType


Example:
DECLARE Counter AS INTEGER
DECLARE StudentName AS STRING
DECLARE Score AS REAL
Constants: Values that do not change during execution.

CONSTANT ConstantName = Value


Example:
CONSTANT PI = 3.14159
CONSTANT MaxStudents = 100

2.3 Identifiers (Naming Rules)


Identifiers are names given to variables, constants, functions, and procedures. Follow these
rules[3]:
Mixed case (PascalCase): Start with capital letter, then camelCase
✅ Correct: FirstName, StudentScore, TotalAmount
❌ Wrong: first_name, studentScore, 1stName
Only letters (A–Z, a–z) and digits (0–9)
Must start with a letter (not a digit)
No special characters (no underscores, hyphens, spaces, accented letters)

Part 3: Operators and Expressions


3.1 Arithmetic Operators
Operator Meaning Example Result
+ Addition 5+3 8
- Subtraction 5-3 2
* Multiplication 5*3 15
/ Division 15 / 3 5
MOD Modulo (remainder) 17 MOD 5 2
DIV Integer division 17 DIV 5 3

Table 2: Arithmetic Operators


Example:
Total ← 10 + 5 // Total is 15
Remainder ← 20 MOD 6 // Remainder is 2

3.2 Comparison Operators


Comparison operators return BOOLEAN values (TRUE or FALSE)[3]:

Operator Meaning Example Result


= Equal to 5=5 TRUE
<> Not equal to 5 <> 3 TRUE
< Less than 3<5 TRUE
> Greater than 5>3 TRUE
<= Less than or equal 5 <= 5 TRUE
>= Greater than or equal 5 >= 3 TRUE

Table 3: Comparison Operators


Example:
IF Age >= 18 THEN
OUTPUT "Adult"
ENDIF

3.3 Logical Operators


Logical operators work with BOOLEAN values[3]:
Operator Meaning Truth Table
Both conditions TRUE AND TRUE = TRUE; otherwise
AND
TRUE FALSE
OR At least one TRUE FALSE OR TRUE = TRUE; case-by-case
NOT TRUE = FALSE; NOT FALSE =
NOT Inverts BOOLEAN
TRUE

Table 4: Logical Operators

Examples:
IF Age >= 18 AND HasLicense = TRUE THEN
OUTPUT "Can drive"
ENDIF
IF Status = "Student" OR Status = "Staff" THEN
OUTPUT "Allowed entry"
ENDIF
IF NOT Complete THEN
OUTPUT "Task pending"
ENDIF

3.4 Order of Operations


Pseudocode follows standard operator precedence[3]:
1. Parentheses ( )
2. NOT
3. Multiplication, Division (*, /, MOD, DIV)
4. Addition, Subtraction (+, -)
5. Comparison operators (=, <>, <, >, <=, >=)
6. AND
7. OR
Example:
// Without parentheses: multiplication before addition
Result ← 2 + 3 * 4 // = 2 + 12 = 14

// With parentheses: addition before multiplication


Result ← (2 + 3) * 4 // = 5 * 4 = 20

Part 4: Input and Output


4.1 INPUT Statement
The INPUT statement reads data from the user and stores it in a variable[3]:

INPUT VariableName
Example:
INPUT StudentName
INPUT Age
INPUT Score
In context:
OUTPUT "Enter your name:"
INPUT Name
OUTPUT "Enter your age:"
INPUT Age

4.2 OUTPUT Statement


The OUTPUT statement displays data to the user. It can output variables, strings, or
expressions[3]:

OUTPUT Value(s)
Examples:
OUTPUT "Hello, World!" // Outputs text
OUTPUT StudentName // Outputs variable
OUTPUT "Your score is: ", Score // Outputs text and variable
OUTPUT Total / Count // Outputs expression (average)
OUTPUT Total, " out of ", Maximum // Multiple values
Key formatting:

Text strings are enclosed in double quotes "..."


Multiple outputs are separated by commas
Each OUTPUT statement displays on a new line

Part 5: Assignment
5.1 The Assignment Operator
The assignment operator ← assigns a value to a variable[3]:
VariableName ← Value
The value on the right is evaluated, then stored in the variable on the left.

Examples:
Counter ← 0 // Assign literal
Total ← Total + 10 // Assign expression
Name ← "John" // Assign string
IsValid ← TRUE // Assign boolean
Average ← Total / Count // Calculate average
Important: Assignment is not the same as comparison.
Assignment: X ← 5 (stores 5 in X)
Comparison: X = 5 (checks if X equals 5; returns TRUE/FALSE)
5.2 Common Assignment Patterns
Incrementing a counter:
Counter ← Counter + 1
Accumulating a total:
Total ← Total + NextValue
Swapping two variables:
Temp ← A
A←B
B ← Temp

Part 6: Selection (Conditional Statements)


6.1 Simple IF...THEN...ENDIF
Executes a block if a condition is TRUE[3]:

IF Condition THEN
// Statements
ENDIF
Example:
INPUT Age
IF Age >= 18 THEN
OUTPUT "You are an adult"
ENDIF
Indentation: Statements inside the IF block are indented by 2 spaces.

6.2 IF...THEN...ELSE...ENDIF
Executes one block if condition is TRUE, another if FALSE[3]:

IF Condition THEN
// Statements (if TRUE)
ELSE
// Statements (if FALSE)
ENDIF
Example:
INPUT Score
IF Score >= 50 THEN
OUTPUT "Pass"
ELSE
OUTPUT "Fail"
ENDIF
6.3 Nested IF Statements
IF statements can be nested inside other IF statements[3]:
IF OuterCondition THEN
IF InnerCondition THEN
// Nested statements
ENDIF
ENDIF
Example:
INPUT Age
INPUT HasLicense
IF Age >= 18 THEN
IF HasLicense = TRUE THEN
OUTPUT "Can drive"
ELSE
OUTPUT "Cannot drive without license"
ENDIF
ELSE
OUTPUT "Too young to drive"
ENDIF

6.4 CASE...OF...OTHERWISE...ENDCASE
Used when testing a single variable against multiple values[3]:
CASE Variable OF
Value1:
// Statements for Value1
Value2:
// Statements for Value2
Value3:
// Statements for Value3
OTHERWISE
// Default statements
ENDCASE
Example:
INPUT Choice
CASE Choice OF
1:
OUTPUT "You chose Option 1"
2:
OUTPUT "You chose Option 2"
3:
OUTPUT "You chose Option 3"
OTHERWISE
OUTPUT "Invalid choice"
ENDCASE

Indentation rule: Statements after each colon are indented by 2 spaces.


Part 7: Iteration (Loops)
Loops repeat a block of code based on a condition. Cambridge recognizes three loop
types[3].

7.1 FOR Loop


Used when the number of iterations is known in advance[3]:
FOR Index ← StartValue TO EndValue
// Statements
NEXT Index
The loop variable (Index) automatically increments by 1 each iteration.

Examples:
Simple count:
FOR I ← 1 TO 10
OUTPUT I
NEXT I
// Outputs: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
Sum numbers 1 to 100:
DECLARE Total AS INTEGER
Total ← 0
FOR Number ← 1 TO 100
Total ← Total + Number
NEXT Number
OUTPUT "Sum is: ", Total

Key points:
The loop variable must be INTEGER
Values are inclusive (both StartValue and EndValue are used)
If StartValue > EndValue, the loop does not execute
If StartValue = EndValue, the loop executes once

7.2 WHILE...DO...ENDWHILE
Used when the number of iterations is unknown but you check a condition before each
iteration[3]:

WHILE Condition DO
// Statements
ENDWHILE
The condition is tested before each iteration. If false, the loop skips.
Examples:

Count down from 10 to 1:


Counter ← 10
WHILE Counter > 0 DO
OUTPUT Counter
Counter ← Counter - 1
ENDWHILE
Input validation (keep asking until valid):
WHILE IsValid = FALSE DO
OUTPUT "Enter a number 1-10:"
INPUT Number
IF Number >= 1 AND Number <= 10 THEN
IsValid ← TRUE
ENDIF
ENDWHILE

Key points:
Condition tested before each iteration
Loop may never execute if condition is initially FALSE
Use when number of repetitions is unknown

7.3 REPEAT...UNTIL
Used when the number of iterations is unknown but you want the loop to execute at least
once[3]:
REPEAT
// Statements
UNTIL Condition

The condition is tested after each iteration. The loop repeats until the condition becomes
TRUE.
Example:
Menu loop:
REPEAT
OUTPUT "1. Start"
OUTPUT "2. Exit"
OUTPUT "Enter choice:"
INPUT Choice
UNTIL Choice = 2

Key points:
Loop executes at least once
Condition tested after each iteration
Loop repeats until condition is TRUE (opposite of WHILE)
Use for "do-while" style loops
7.4 Loop Comparison Table
Condition Executes 0
Loop Type When to Use
Check Times?
Before
FOR Known iterations Yes, if start > end
(implicit)
Unknown, condition- Yes, if initially
WHILE Before
based false
REPEAT At least one No, always runs
After
UNTIL execution once

Table 5: Loop Comparison

7.5 Nested Loops


Loops can be nested (loops inside loops)[3]:

FOR I ← 1 TO 3
FOR J ← 1 TO 2
OUTPUT I, " ", J
NEXT J
NEXT I
Output:
11
12
21
22
31
32

Part 8: Arrays
8.1 What is an Array?
An array is a collection of variables of the same data type, stored in contiguous memory
locations and accessed by index[3]:
1D Array: A list of elements (like a row)
2D Array: A table of elements (like rows and columns)
Indexed: Elements accessed by position (index)

8.2 Declaring Arrays


1D Array Declaration:
DECLARE ArrayName[1 : HighestIndex] OF DataType

Example:
DECLARE Scores[1 : 50] OF INTEGER
DECLARE Names[1 : 30] OF STRING
Note: Arrays are INDEXED FROM 1 by default in Cambridge pseudocode (not 0)[3].

2D Array Declaration:
DECLARE ArrayName[1 : RowCount, 1 : ColumnCount] OF DataType
Example:
DECLARE Matrix[1 : 5, 1 : 5] OF INTEGER // 5x5 table

8.3 Accessing Array Elements


1D Access:
Scores[1] ← 85 // Store in first position
Total ← Scores[1] // Retrieve value
2D Access:
Matrix[2, 3] ← 10 // Row 2, Column 3
Value ← Matrix[2, 3]

8.4 Initializing Arrays


Set all elements to 0:
FOR Index ← 1 TO 50
Scores[Index] ← 0
NEXT Index
Set all elements to empty string:
FOR Index ← 1 TO 30
Names[Index] ← ""
NEXT Index

8.5 Array Traversal (Loop Through All Elements)


FOR Index ← 1 TO 50
OUTPUT Scores[Index]
NEXT Index

8.6 Array Operations


Finding the sum of all elements:
DECLARE Scores[1 : 50] OF INTEGER
DECLARE Total AS INTEGER
DECLARE Count AS INTEGER
Total ← 0
Count ← 0
FOR Index ← 1 TO 50
IF Scores[Index] > 0 THEN // Assume 0 means no score
Total ← Total + Scores[Index]
Count ← Count + 1
ENDIF
NEXT Index
OUTPUT "Total: ", Total
OUTPUT "Count: ", Count
OUTPUT "Average: ", Total / Count
Finding the maximum value:
DECLARE Scores[1 : 50] OF INTEGER
DECLARE Max AS INTEGER
Max ← Scores[1] // Assume first is max
FOR Index ← 2 TO 50
IF Scores[Index] > Max THEN
Max ← Scores[Index]
ENDIF
NEXT Index
OUTPUT "Maximum score: ", Max

Searching for a value (Linear Search):


DECLARE Names[1 : 30] OF STRING
DECLARE Found AS BOOLEAN
DECLARE SearchTerm AS STRING
INPUT SearchTerm
Found ← FALSE
FOR Index ← 1 TO 30
IF Names[Index] = SearchTerm THEN
OUTPUT "Found at position: ", Index
Found ← TRUE
ENDIF
NEXT Index
IF Found = FALSE THEN
OUTPUT "Not found"
ENDIF

Part 9: Procedures and Functions


9.1 What is a Procedure?
A procedure is a reusable block of code that performs a specific task. It can accept
parameters but does not return a value[3].

Declaring a procedure:
PROCEDURE ProcedureName(Parameter1, Parameter2, ...)
// Statements
ENDPROCEDURE
Calling a procedure:
CALL ProcedureName(Argument1, Argument2, ...)
Example:
PROCEDURE DisplayWelcome(Name, Age)
OUTPUT "Welcome, ", Name
OUTPUT "Your age is: ", Age
ENDPROCEDURE
// Call the procedure
CALL DisplayWelcome("John", 25)
CALL DisplayWelcome("Sarah", 30)

9.2 Parameters: Pass by Value vs Pass by Reference


Pass by Value: The procedure receives a copy of the value. Changes inside the procedure do
not affect the original variable[3].
DECLARE X AS INTEGER
X ← 10
PROCEDURE AddTen(Number) // Pass by value
Number ← Number + 10
ENDPROCEDURE
CALL AddTen(X)
OUTPUT X // Still 10

Pass by Reference: The procedure receives a reference to the original variable. Changes
do affect the original[3].
DECLARE X AS INTEGER
X ← 10
PROCEDURE AddTenRef(BYREF Number) // Pass by reference
Number ← Number + 10
ENDPROCEDURE
CALL AddTenRef(X)
OUTPUT X // Now 20

9.3 What is a Function?


A function is like a procedure but returns a single value[3]:

Declaring a function:
FUNCTION FunctionName(Parameter1, Parameter2, ...) RETURNS DataType
// Statements
RETURN Value
ENDFUNCTION
Using a function:
Result ← FunctionName(Argument1, Argument2, ...)
Example:
FUNCTION CalculateAverage(Total, Count) RETURNS REAL
RETURN Total / Count
ENDFUNCTION

// Using the function


DECLARE Avg AS REAL
Avg ← CalculateAverage(150, 3) // Avg = 50
OUTPUT "Average: ", Avg
Part 10: Common Built-in Routines
Cambridge pseudocode includes built-in functions for common operations[3]:

String Operations
Function Description Example
Returns number of
LENGTH(String) LENGTH("Hello") = 5
characters
SUBSTRING(String, SUBSTRING("Hello", 2,
Extracts substring
Start, Length) 3) = "ell"
Converts to UCASE("Hello") =
UCASE(String)
uppercase "HELLO"
Converts to
LCASE(String) LCASE("Hello") = "hello"
lowercase
Finds position of POSITION('l', "Hello") =
POSITION(Char, String)
character 3

Table 6: String Built-in Routines

Numeric Operations
Function Description Example
ABS(Number) Absolute value ABS(-5) = 5
INT(Number) Integer part INT(3.7) = 3
ROUND(Number, Rounds to decimal ROUND(3.1416, 2) =
Places) places 3.14
RANDOM() Random number 0--1 RANDOM() = 0.456
SQRT(Number) Square root SQRT(9) = 3

Table 7: Numeric Built-in Routines

Part 11: Common Pseudocode Patterns & Exam


Techniques
11.1 Input Validation
Ensure user input is valid before processing:
REPEAT
OUTPUT "Enter age (1-120):"
INPUT Age
UNTIL Age >= 1 AND Age <= 120
11.2 Counting Loop with Exit Condition
Count occurrences or loop until a condition:
Count ← 0
FOR I ← 1 TO 100
IF Scores[I] > 50 THEN
Count ← Count + 1
ENDIF
NEXT I
OUTPUT "Passed: ", Count

11.3 Accumulation (Sum, Total)


Add values during a loop:

Total ← 0
FOR I ← 1 TO ArraySize
Total ← Total + Array[I]
NEXT I
OUTPUT "Sum: ", Total

11.4 Min/Max Finding


Track smallest or largest value:
Max ← Array[1]
FOR I ← 2 TO ArraySize
IF Array[I] > Max THEN
Max ← Array[I]
ENDIF
NEXT I

11.5 Linear Search


Find an item in an array:
Found ← FALSE
FOR I ← 1 TO ArraySize
IF Array[I] = SearchValue THEN
Found ← TRUE
OUTPUT "Found at index: ", I
ENDIF
NEXT I

11.6 Bubble Sort (Basic Algorithm)


Sort array in ascending order:
FOR I ← 1 TO ArraySize - 1
FOR J ← 1 TO ArraySize - I
IF Array[J] > Array[J + 1] THEN
// Swap
Temp ← Array[J]
Array[J] ← Array[J + 1]
Array[J + 1] ← Temp
ENDIF
NEXT J
NEXT I

Part 12: Common Errors & How to Spot Them


Error Type 1: Wrong Loop Type
❌ Error: Using FOR when iterations are unknown.
✅ Fix: Use WHILE or REPEAT UNTIL.

❌ Error: Using WHILE when count is known.


✅ Fix: Use FOR for clarity.

Error Type 2: Missing Loop Condition


❌ Missing:
WHILE True DO // No exit condition!
OUTPUT "Infinite loop"
ENDWHILE

✅ Fix:
WHILE Counter <= 10 DO
OUTPUT Counter
Counter ← Counter + 1
ENDWHILE

Error Type 3: Off-by-One Errors


❌ Error:
FOR I ← 1 TO 10 // Outputs 1–10 (correct)
FOR I ← 0 TO 9 // In Cambridge, arrays are INDEXED FROM 1
✅ Fix: Use INDEXED FROM 1 for Cambridge.

Error Type 4: Incorrect Data Type Comparison


❌ Error:
IF "5" > 4 THEN // Can't compare STRING and INTEGER
✅ Fix:
IF 5 > 4 THEN // Both are INTEGER

Error Type 5: Missing ENDIF, ENDWHILE, etc.


❌ Missing:
IF Age >= 18 THEN
OUTPUT "Adult"
// Missing ENDIF!
✅ Fix:
IF Age >= 18 THEN
OUTPUT "Adult"
ENDIF

Part 13: Past Paper Questions with Solutions


Question 1: Error Identification (May/June 2024, Variant 1)
Question: Identify and correct four errors in this pseudocode:
01 DECLARE Limit AS INTEGER
02 Limit ← RANDOM() * 20 + 1
03 DECLARE Value, Total AS INTEGER
04 DECLARE Loop AS STRING
05 Total ← 0
06
07 FOR Loop ← 1 TO Limit
08 INPUT "Value:"
09 Total ← Total * Value // ERROR 1
10
11 NEXT Loop
12
13 OUTPUT "The total of the numbers entered is ", Total
14 OUTPUT "The average of the numbers entered is ", Total / Limit
Errors & Corrections:

Error
Line Problem Correction
#
RANDOM() needs INT
1 02 INT(RANDOM() * 20) + 1
wrapper
2 04 Loop should be INTEGER DECLARE Loop AS INTEGER
INPUT Value or OUTPUT then
3 08 Wrong INPUT format
INPUT
4 09 Uses * instead of + Total ← Total + Value

Table 8: Error Analysis -- Question 1

A Solution:*
01 DECLARE Limit AS INTEGER
02 Limit ← INT(RANDOM() * 20) + 1
03 DECLARE Value, Total AS INTEGER
04 DECLARE Loop AS INTEGER
05 Total ← 0
06
07 FOR Loop ← 1 TO Limit
08 OUTPUT "Enter value:"
09 INPUT Value
10 Total ← Total + Value
11 NEXT Loop
12
13 OUTPUT "The total of the numbers entered is ", Total
14 OUTPUT "The average of the numbers entered is ", Total / Limit

Question 2: Writing Pseudocode for Exam Scenario


Question: Write pseudocode to:
Accept input of 5 exam scores (out of 100)
Calculate and display the average
Display how many scores are above average
A Solution:*
DECLARE Scores[1 : 5] OF INTEGER
DECLARE Total AS INTEGER
DECLARE Average AS REAL
DECLARE AboveAverage AS INTEGER
DECLARE Index AS INTEGER

// Input scores
Total ← 0
FOR Index ← 1 TO 5
OUTPUT "Enter score ", Index, ":"
INPUT Scores[Index]
Total ← Total + Scores[Index]
NEXT Index
// Calculate average
Average ← Total / 5
// Display average
OUTPUT "Average score: ", ROUND(Average, 2)

// Count scores above average


AboveAverage ← 0
FOR Index ← 1 TO 5
IF Scores[Index] > Average THEN
AboveAverage ← AboveAverage + 1
ENDIF
NEXT Index
// Display count
OUTPUT "Scores above average: ", AboveAverage
Marking points (A):*

✅ Correct array declaration with INDEXED FROM 1


✅ INPUT within loop for 5 scores
✅ Accumulation of total
✅ Correct average calculation (division by 5)
✅ ROUND() for display
✅ Comparison logic (> Average)
✅ Count increment
✅ Clear comments and meaningful variable names

Question 3: Logic Error Finding and Fixing


Question: This pseudocode should find the largest number. Find and fix the error:
DECLARE Numbers[1 : 10] OF INTEGER
DECLARE Max AS INTEGER
DECLARE Index AS INTEGER
Max ← 0

FOR Index ← 1 TO 10
IF Numbers[Index] > Max THEN
Max ← Numbers[Index]
ENDIF
NEXT Index
OUTPUT "Maximum: ", Max
Error Analysis:

If all numbers are negative (e.g., -5, -3, -10), Max stays 0, which is wrong.
A Fix:*
Max ← Numbers[1] // Start with first element, not 0
FOR Index ← 2 TO 10
IF Numbers[Index] > Max THEN
Max ← Numbers[Index]
ENDIF
NEXT Index

OUTPUT "Maximum: ", Max

Question 4: 15-Mark Long Question (Typical Structure)


Question: Write pseudocode for a simple number guessing game:
System generates a random number 1–100
User has 5 attempts to guess it
Each guess: display "too high", "too low", or "correct"
At end: display attempts used or "game over"
A Solution:*

// Declare variables
DECLARE RandomNumber AS INTEGER
DECLARE Guess AS INTEGER
DECLARE Attempts AS INTEGER
DECLARE GameOver AS BOOLEAN
// Initialize
RandomNumber ← INT(RANDOM() * 100) + 1
Attempts ← 0
GameOver ← FALSE

OUTPUT "Welcome to Number Guess!"


OUTPUT "I'm thinking of a number 1-100"
OUTPUT "You have 5 attempts"
OUTPUT ""
// Game loop
REPEAT
Attempts ← Attempts + 1
OUTPUT "Attempt ", Attempts, " - Enter your guess:"
INPUT Guess
IF Guess = RandomNumber THEN
OUTPUT "Correct! You won in ", Attempts, " attempts"
GameOver ← TRUE
ELSE
IF Guess < RandomNumber THEN
OUTPUT "Too low, try again"
ELSE
OUTPUT "Too high, try again"
ENDIF
ENDIF

UNTIL GameOver = TRUE OR Attempts = 5


// End game message
IF GameOver = FALSE THEN
OUTPUT "Game Over! The number was: ", RandomNumber
OUTPUT "You used all 5 attempts"
ENDIF
Marking points (A):*

✅ Proper variable declarations


✅ Random number generation (INT and RANDOM)
✅ Loop with dual exit conditions (REPEAT UNTIL)
✅ Nested IF for comparisons
✅ Attempt counter incrementing
✅ Clear, descriptive OUTPUT messages
✅ Comments explaining logic
✅ Proper indentation (2 spaces)
Part 14: Revision Checklist
Use this checklist to verify your pseudocode knowledge before the exam[1][2][3]:

Data Types & Variables


[ ] Can declare variables with correct syntax
[ ] Understand all five primitive types (INTEGER, REAL, STRING, CHAR, BOOLEAN)
[ ] Can use constants correctly
[ ] Follow identifier naming rules (PascalCase, no special chars)

Operators
[ ] Understand arithmetic (+, -, *, /, MOD, DIV)
[ ] Understand comparison (=, <>, <, >, <=, >=)
[ ] Understand logical (AND, OR, NOT)
[ ] Know operator precedence

Input/Output
[ ] INPUT statement for reading data
[ ] OUTPUT statement for displaying data
[ ] Multiple outputs in one statement (commas)

Selection
[ ] Simple IF...ENDIF
[ ] IF...ELSE...ENDIF
[ ] Nested IFs
[ ] CASE...ENDCASE

Iteration
[ ] FOR loop (known count)
[ ] WHILE loop (condition-based)
[ ] REPEAT UNTIL (at least once)
[ ] Nested loops
[ ] Choose correct loop type for problem

Arrays
[ ] 1D array declaration (INDEXED FROM 1)
[ ] 2D array declaration
[ ] Accessing elements
[ ] Array traversal
[ ] Min/max, sum, search
Procedures & Functions
[ ] Declare procedures (no return)
[ ] Declare functions (RETURNS type)
[ ] Parameters (BYVALUE vs BYREF)
[ ] Call procedures/functions

Common Patterns
[ ] Input validation loops
[ ] Accumulation
[ ] Min/max finding
[ ] Linear search
[ ] Bubble sort basics

Part 15: Exam Strategy & Time Management


Paper 2 Structure (1 hour 45 minutes, 75 marks)
Typical breakdown:
Questions 1–9 (Short answer & error identification): ~50 marks, 60 minutes
Error spotting (usually 4–6 errors to find)
Tracing algorithms (predict output)
Short pseudocode snippets
Questions 10–11 (Structured pseudocode): ~25 marks, 45 minutes
15 marks for full problem-solving question
10 marks for related short questions

How to Maximize Marks: 10 Key Tips


1. Read questions 2–3 times before answering
First read: understand what's asked
Second read: identify key requirements (loops? arrays? functions?)
Third read: plan your approach

2. For error-spotting: list only the error, not full rewrites


Instead of rewriting entire lines, mark errors directly on the paper
Example: "Line 9: * should be +" (saves time)
3. For tracing: step through line by line on paper

Create a table of variable values after each iteration


This shows examiners your logic and earns partial marks even if final answer is
wrong
4. For short pseudocode: prioritize correct logic over perfect syntax
A correct algorithm with minor syntax issues (e.g., forgot ENDIF) still earns most
marks
Examiners reward structure and logic, not punctuality
5. For the 15-mark question: write a brief plan first
Inputs, Processing, Outputs (IPO method)
This takes 2 minutes but prevents major logic errors

6. Always write pseudocode, not code


Don't use Python, Java, or any specific language syntax
Use exactly Cambridge's keywords (FOR, WHILE, DECLARE, etc.)
7. Use meaningful variable names and comments

Instead of X, use StudentScore


Comments like // Calculate average earn clarity marks
8. Double-check loop endings (ENDIF, ENDWHILE, ENDCASE, ENDPROCEDURE)
Missing endings is common; a quick 30-second scan catches them

9. For arrays, always check INDEXED FROM 1 and avoid index errors
Example: if array has 50 elements, loop should go 1 TO 50, not 0 TO 49
10. If you get stuck, skip and return later

Don't waste 10 minutes on a 3-mark question


Maximize total marks by answering easier questions first

Time Allocation Guide

Question Mark
Section Time Approach
s s
Short 60
1–9 50 6–7 min/question
questions min
Long 25
10 15 Plan, code, review
question min
Short follow- 20 Apply same logic as
11 10
up min Q10

A* Scoring Benchmark
Short questions (1–9): Aim for 45–50 marks (90%+)
Careless errors cost 1–2 marks; be meticulous
Question 10 (15-mark): Aim for 13–15 marks (87%+)
Strong logic, clear structure, all loops closed
Question 11 (10-mark): Aim for 9–10 marks (90%+)
Related to Q10; similar technique
Total A threshold:* ~110–115 out of 150 marks across both papers (Paper 1 + Paper 2)
Final Tips for Success
The Night Before the Exam
✅ Review your revision checklist (Part 14); mark weak areas
✅ Re-read one complex pseudocode example (Part 13, Question 4)
✅ Write out 3 common patterns from memory: validation loop, accumulation, search
✅ Get 7–8 hours sleep (memory consolidation)
✅ Do NOT cram new topics

During the Exam


✅ Allocate time: 60 min for Q1–9, 45 min for Q10–11
✅ Read the full question before starting
✅ Plan big questions (IPO method)
✅ Write clearly with proper indentation
✅ If stuck after 3 minutes, move on
✅ Leave time (10 min) for review at the end

Common Last-Minute Errors to Avoid


❌ Using variable names starting with numbers (1stScore → wrong)
❌ Mixing up = (comparison) and ← (assignment)
❌ Forgetting INDEXED FROM 1 for arrays
❌ Writing code instead of pseudocode
❌ Missing ENDIF, ENDWHILE, ENDCASE
❌ Infinite loops (no exit condition)
❌ Comparing different data types (STRING and INTEGER)

References
[1] Cambridge International Education. (2023–2025). Cambridge IGCSE Computer Science
Syllabus (0478). Retrieved from [Link]
[2] Cambridge International Education. (2026). Pseudocode Guide for Teachers. Retrieved
from [Link]
[Link]

[3] Learning resources for IGCSE Computer Science 0478, compiled from official Cambridge
syllabi and past paper mark schemes (2023–2025 sessions).

Document Information
Last Updated: December 2025
Exam Board: Cambridge International Education (IGCSE 0478)
Paper: Paper 2 (Algorithms, Programming and Logic)
Duration: 1 hour 45 minutes
Marks: 75 (combined with Paper 1 for 150 total)
Study Schedule (7–10 Days to Exam)
Day 1–2: Read Parts 1–4 (fundamentals, data types, operators, I/O) → Practice basic
declarations and OUTPUT statements
Day 3–4: Read Parts 5–7 (assignment, selection, iteration) → Practice simple and nested IF,
all loop types

Day 5–6: Read Parts 8–9 (arrays, procedures, functions) → Code array operations and pass-
by-value vs reference
Day 7: Read Parts 10–11 (built-ins, common patterns) → Practice min/max, search, sort
Day 8–9: Work Part 13 (past paper questions) → Solve Questions 1–3 and attempt Question
4 in exam conditions

Day 10: Use Part 14 (checklist) → Identify weak areas, re-read those sections, do final
revision of common errors

Good luck with your revision! Remember: Logic over syntax, practice past papers, and
read questions carefully.

Common questions

Powered by AI

Modularity through procedures and functions enhances readable and maintainable algorithms by encapsulating specific tasks into distinct blocks. This separation of concerns allows for easier debugging, updating, and understanding of code, as each modular section can be altered independently without affecting the entire system, promoting reuse and efficient problem-solving .

Arrays in pseudocode allow for efficient handling and manipulation of data collections by offering indexed storage for similar data types, facilitating operations such as searching, sorting, and traversing. Arrays are typically declared with a specified range and data type and can be manipulated using loops for tasks like populating values, computing totals, or searching for elements. This structure aids in managing large datasets systematically .

Input validation is crucial as it ensures that algorithms operate on valid and expected data, preventing errors during execution. It is typically implemented using loops like WHILE or REPEAT UNTIL to repeatedly prompt for input until valid criteria are met, thus guaranteeing that an algorithm's logic is upheld under various conditions .

Pseudocode prepares students for A-Level studies and industry by reinforcing logical problem-solving skills, independent of programming language syntax. Its universal approach develops the ability to design algorithms that can be adapted into any language, fostering a deep understanding of fundamental computational concepts. This skillset is critical for complex algorithm development in both advanced studies and professional environments .

Pseudocode benefits algorithm design by abstracting the syntactical complexities of specific programming languages, allowing for a clear focus on the logical steps required to solve problems. It prepares students for higher-level courses and adapts easily for industry use, where developers often sketch algorithms in pseudocode before coding. This practice facilitates collaboration, communication, and rapid algorithm prototyping across different languages and systems .

Pseudocode functions as a universal problem-solving tool by providing a language-agnostic method to describe algorithms, allowing students to focus on logic and structure without worrying about the syntax of specific programming languages. In Cambridge IGCSE exams, pseudocode is used to test students' understanding of algorithms, where logic is prioritized over syntax, which is crucial for developing critical thinking and problem-solving skills .

Built-in string and numeric functions enhance pseudocode by providing versatile tools for manipulating data, such as altering strings or performing mathematical operations effortlessly. This availability streamlines coding processes in exams, allowing students to focus on algorithm logic without implementing these functionalities from scratch, thus aligning their focus on problem-solving rather than technical detail .

The primary considerations include the number of repetitions and when the condition is tested. A WHILE loop is used for unknown iterations where the condition is checked before execution, allowing for zero iterations. FOR loops are selected for a known number of iterations. REPEAT UNTIL loops are used when the loop must execute at least once, testing conditions after each iteration .

In 'pass by value', a procedure receives a copy of the argument, meaning changes inside the procedure do not affect the original variable. Conversely, 'pass by reference' means the procedure receives a reference to the original data, so changes inside the procedure affect the original variable. This distinction is crucial for algorithm development because it influences how data is manipulated across functions, affecting program behavior and performance .

Common errors include wrong loop types (e.g., using FOR instead of WHILE when iterations are unknown), missing ENDIF/ENDWHILE, off-by-one errors, incorrect data type comparisons, and mixing assignment with equality checks. Avoiding these errors involves thoroughly understanding loop purposes, ensuring all control structures are properly closed, and verifying correct use of operators and data types .

You might also like