Every program starts with data: variables that change, constants that do not, and expressions that combine them. Learn to write each statement exactly as the 9618 pseudocode guide does, turn a flowchart or structured English into pseudocode, and use the built-in functions the exam gives you.
A variable is a named memory location whose value can change while the program runs; declare it with DECLARE Name : TYPE and give it a value with the assignment operator ←. A constant is declared once with CONSTANT Name = value, using a literal only, and can never be changed. Expressions combine values with arithmetic operators (+ - * / DIV MOD), relational operators and the logical operators AND, OR, NOT. Built-in functions and library routines are pre-written, pre-tested subroutines such as LENGTH, MID and INT.
Exam questions give you a design as a program flowchart or as structured English and ask for pseudocode. Work through it one step at a time: declarations and constants first, then one statement for each input, process and output.
CONSTANT TicketPrice = 8.50 CONSTANT BookingFee = 1.20 DECLARE Tickets : INTEGER DECLARE Cost : REAL OUTPUT "How many tickets?" INPUT Tickets Cost ← Tickets * TicketPrice + BookingFee OUTPUT "Total to pay: ", Cost
DECLARE Cost : REAL names a variable and fixes its data type. It does not give it a value.Total ← 0 before a running total is built up.← evaluates the expression on the right, then stores the result in the variable on the left.CONSTANT TicketPrice = 8.50. Only a literal may follow the =; never a variable, another constant or an expression.INPUT Tickets reads from the keyboard; OUTPUT can show several values separated by commas.CONSTANT HourlyRate = 12.50.DECLARE Hours : INTEGER and DECLARE Pay : REAL.INPUT Hours then Pay ← Hours * HourlyRate.OUTPUT "Pay: ", Pay. With 6 hours, 6 × 12.50 = 75.00.CONSTANT HourlyRate = 12.50 DECLARE Hours : INTEGER DECLARE Pay : REAL INPUT Hours Pay ← Hours * HourlyRate OUTPUT "Pay: ", PayWith 6 hours the output is Pay: 75.00 (many languages show it as 75.0).
CONSTANT VAT = Price * 0.2 is not allowed: a constant must be a literal. And a constant can never appear on the left of ← later in the program.
An expression is anything that evaluates to a single value. Know exactly what each operator returns, because examiners love asking for the value of an expression or its data type.
| Operator | Meaning | Example (A = 17, B = 5) | Result |
|---|---|---|---|
| + − * | add, subtract, multiply | A + B * 2 | 27 (* before +) |
| / | division: always a REAL result | A / B | 3.4 |
| DIV | integer division: the whole-number quotient | A DIV B | 3 |
| MOD | the remainder after integer division | A MOD B | 2 |
| > < >= <= = <> | relational: the result is BOOLEAN | A <> B | TRUE |
| AND, OR, NOT | logical: BOOLEAN in, BOOLEAN out | (A > 15) AND NOT (B = 5) | FALSE |
10 / 2 gives 5.0, a REAL. Use DIV if you need an INTEGER.N MOD 2 = 0 is TRUE exactly when N is even.Minutes ← Seconds DIV 60 gives 7 and Secs ← Seconds MOD 60 gives 17. Check: 7 × 60 + 17 = 437.17 / 5 is 3.4, not 3. If a question says the result must be an INTEGER, the mark is for DIV (or INT), not /.
Four quick checks. Each correct answer earns XP and records this skill on your profile.
What is the value of 23 MOD 4?
Which is a valid constant declaration in 9618 pseudocode?
What does MID("COMPUTER", 4, 3) return?
In the lab, the program that reverses a word is given "stressed". What does it output?
Built-in functions and library routines are subroutines that are already written, tested and ready to use: they save time and reduce errors. String functions are always given in the exam paper, but you should recognise these from the 9618 guide. Try the lab's reverse-a-word program (choose MID and a STEP -1 loop) to watch MID pick out one character at a time.
| Function | Returns | Example |
|---|---|---|
| LENGTH(ThisString) | INTEGER: number of characters | LENGTH("Lucid STEM") returns 10 |
| MID(ThisString, x, y) | STRING of length y starting at position x | MID("PROGRAM", 4, 3) returns "GRA" |
| RIGHT(ThisString, x) | STRING: the rightmost x characters | RIGHT("PROGRAM", 3) returns "RAM" |
| UCASE(ThisChar), LCASE(ThisChar) | CHAR in upper or lower case | UCASE('q') returns 'Q' |
| INT(x) | INTEGER: the integer part of x | INT(7.9) returns 7 |
| RAND(x) | REAL from 0 up to, but not including, x | RAND(6) may return 4.27 |
// a random whole number from 1 to 6 Dice ← INT(RAND(6)) + 1 // join strings with & Message ← "You rolled " & "a dice"
MID(Surname, 1, 3) gives "Oka".RIGHT(BirthYear, 2) gives "08".UserName ← MID(Surname, 1, 3) & RIGHT(BirthYear, 2).INT(RAND(6)) + 1 always gives a whole number from 1 to 6.In the 9618 guide UCASE and LCASE take a single CHAR, and string positions start at 1. To change a whole string, loop through it with MID one character at a time.
Unlocks once the four checks above are done. Worth more XP, written to AS Paper 1 and Paper 2 standard.
Which expression always gives a random whole number from 1 to 10 inclusive?
What is the data type of the result of 9 / 3 in 9618 pseudocode?
Age holds 19. What is the value of (Age >= 13) AND NOT (Age > 19)?
Give the best reason for declaring the VAT rate as a constant rather than writing 0.2 throughout the program.
This skill is now recorded on your profile. Keep the chain going.