Putting it together
One program uses several constructs
- A 9618 answer mixes
DECLARE,←,IF…THEN,FORandOUTPUT. - Indent the body of a loop. Put
THENon theIFline. - A short comment with
//says what a block is for.
// Total the five marks, then say whether the total reaches 20.
DECLARE Mark : ARRAY[1:5] OF INTEGER
Mark[1] ← 4
Mark[2] ← 8
Mark[3] ← 6
Mark[4] ← 2
Mark[5] ← 5
DECLARE Total : INTEGER
DECLARE I : INTEGER
Total ← 0
FOR I ← 1 TO 5
Total ← Total + Mark[I]
NEXT I
OUTPUT "Total = ", Total
IF Total >= 20 THEN
OUTPUT "target met"
ELSE
OUTPUT "below target"
ENDIF
Worked example: plan, then two passes
Question: how many of the five marks are above the average?
- Input: the five marks, stored in an array.
- Process: you cannot compare a mark with the average until you know the average. So loop once to find the total, then loop again to count.
- Output: the average, then the count.
DECLARE Mark : ARRAY[1:5] OF INTEGER
DECLARE Total, Above, I : INTEGER
DECLARE Average : REAL
Mark[1] ← 4
Mark[2] ← 8
Mark[3] ← 6
Mark[4] ← 2
Mark[5] ← 5
// Pass 1: the average needs every mark first
Total ← 0
FOR I ← 1 TO 5
Total ← Total + Mark[I]
NEXT I
Average ← Total / 5
// Pass 2: compare each mark with the average
Above ← 0
FOR I ← 1 TO 5
IF Mark[I] > Average THEN
Above ← Above + 1
ENDIF
NEXT I
OUTPUT "Average = ", Average
OUTPUT "Above average: ", Above
The total is 25, so the average is 5.0. The marks 8 and 6 are above it, so the count is 2. The mark 5 equals the average and is not counted.
Common mistakes
- Setting
Total ← 0inside the loop. It is reset on every pass, so only the last mark is kept. - Counting in the same loop that builds the total. The average is not known yet.
- Using
Iwithout aDECLARE. A 9618 answer declares every variable, loop counters too. - Writing
>=when the question says "above". Check what happens to a value that is exactly equal.
What this course left for A2
- Random files, classes, enumerated types and pointers are in the full 9618 guide.
- They are assessed at A2, not in this AS course.
- The IGCSE course on this site uses the 0478 rules for 2026–2028. Do not copy those into a 9618 answer.
Now you try
- Total an array, then choose a message with
IF.
Independent transfer
The final task has no supplied algorithm. Plan its inputs, processing and outputs, then solve it before opening support. Check more than the sample case.
Difficulty 1/5 · 100 coins + a small bonus on first completion today
The array is filled for you. Output Total = 25 on one line, then target met because 25 is at least 20.
Click Run to see the output here.
Difficulty 2/5 · 140 coins + a small bonus on first completion today
Read five integer marks into Mark : ARRAY[1:5] OF INTEGER. Output how many marks are strictly above their average.
Click Run to see the output here.
Difficulty 3/5 · 200 coins + a small bonus on first completion today
A library has Capacity seats. Read Capacity, then NumberOfGroups (1 to 5), then NumberOfGroups requested group sizes. Accept a positive group only if it fits in the remaining seats. Output yes/no per group, then occupied seats.
Click Run to see the output here.