Skip to content

Cambridge IGCSE · Free tool

Cambridge IGCSE 0478 Pseudocode Compiler

Run Cambridge IGCSE Computer Science 0478 pseudocode online. Write it the way the exam does, add INPUT values, and see output and line-numbered errors instantly. Free, no sign-up.

Cambridge 0478
main.0478
Ready

0478 pseudocode rules

Cambridge IGCSE pseudocode with ← assignment, DECLARE, CASE OF and DIV/MOD functions.
  • Assign with ← (type <-) and declare constants as CONSTANT Name ← value.
  • THEN can sit at the end of the IF line or on the next line; close with ENDIF.
  • FOR loops end with NEXT; arrays are declared like ARRAY[1:10] OF INTEGER.
  • Join strings with &; DIV(a, b) and MOD(a, b) are functions.

0478 example programs

Every example runs exactly as shown. Open one in the editor to change it and run it again.

Total and average of marks

Reads five marks with INPUT inside a FOR loop, keeps a running total and outputs the average.

Input and outputLoops

Open in editor
// Read five marks and output the total and average
DECLARE Mark : INTEGER
DECLARE Total : INTEGER
DECLARE Count : INTEGER
CONSTANT NumberOfMarks <- 5

Total <- 0
FOR Count <- 1 TO NumberOfMarks
  OUTPUT "Enter mark ", Count
  INPUT Mark
  Total <- Total + Mark
NEXT Count

OUTPUT "Total: ", Total
OUTPUT "Average: ", Total / NumberOfMarks
Inputs
12, 15, 9, 18, 11
Output
Enter mark 1
Enter mark 2
Enter mark 3
Enter mark 4
Enter mark 5
Total: 65
Average: 13

Bubble sort

Sorts an array of scores into ascending order with a REPEAT ... UNTIL loop that stops when no swaps are made.

ArraysSortingLoops

Open in editor
// Bubble sort an array into ascending order
DECLARE Scores : ARRAY[1:6] OF INTEGER
DECLARE Temp : INTEGER
DECLARE Index : INTEGER
DECLARE Last : INTEGER
DECLARE Swapped : BOOLEAN

Scores[1] <- 42
Scores[2] <- 7
Scores[3] <- 19
Scores[4] <- 88
Scores[5] <- 3
Scores[6] <- 25

Last <- 5
REPEAT
  Swapped <- FALSE
  FOR Index <- 1 TO Last
    IF Scores[Index] > Scores[Index + 1]
      THEN
        Temp <- Scores[Index]
        Scores[Index] <- Scores[Index + 1]
        Scores[Index + 1] <- Temp
        Swapped <- TRUE
    ENDIF
  NEXT Index
  Last <- Last - 1
UNTIL Swapped = FALSE OR Last = 0

FOR Index <- 1 TO 6
  OUTPUT Scores[Index]
NEXT Index
Output
3
7
19
25
42
88

Menu with CASE OF

Uses CASE OF with CHAR values and an OTHERWISE branch to respond to a menu choice.

SelectionInput and output

Open in editor
// Respond to a menu choice with CASE OF
DECLARE Choice : CHAR

OUTPUT "Enter A, B or C"
INPUT Choice
CASE OF Choice
  'A' : OUTPUT "Add a record"
  'B' : OUTPUT "Browse records"
  'C' : OUTPUT "Close"
  OTHERWISE : OUTPUT "Invalid choice"
ENDCASE
Inputs
B
Output
Enter A, B or C
Browse records

Procedures, functions and strings

Defines a PROCEDURE and a FUNCTION and uses LENGTH, SUBSTRING, UCASE, ROUND, DIV and MOD.

SubroutinesStrings

Open in editor
// Procedures, functions and string handling
FUNCTION Initials(FirstName : STRING, LastName : STRING) RETURNS STRING
  RETURN UCASE(SUBSTRING(FirstName, 1, 1)) & UCASE(SUBSTRING(LastName, 1, 1))
ENDFUNCTION

PROCEDURE Greet(Name : STRING)
  OUTPUT "Hello, ", Name, "! Your name has ", LENGTH(Name), " letters."
ENDPROCEDURE

DECLARE First : STRING
DECLARE Last : STRING

INPUT First
INPUT Last
CALL Greet(First)
OUTPUT "Initials: ", Initials(First, Last)
OUTPUT "7 / 3 rounded: ", ROUND(7 / 3, 2)
OUTPUT "DIV(7, 2) = ", DIV(7, 2), ", MOD(7, 2) = ", MOD(7, 2)
Inputs
ada, lovelace
Output
Hello, ada! Your name has 3 letters.
Initials: AL
7 / 3 rounded: 2.33
DIV(7, 2) = 3, MOD(7, 2) = 1