Cambridge IGCSE · Topic 7 (7-9)
IGCSE Computer Science 0478 / Topic 7 / IGCSE

Say it precisely.

The longest questions ask you to write an algorithm for a scenario, or to change one you are given. Marks come for each working part: prompts and inputs, validation, loops, totals and counts, and clear outputs. Write precisely, in pseudocode, program code or a flowchart.

The key idea

An algorithm must be precise: write Score > Target, not "score is bigger than the target". Build a solution from the standard parts: initialise variables, prompt and input, validate, process inside a suitable loop (totalling, counting, max/min), then output clear results. Use meaningful identifiers. To amend an algorithm, keep what works and add or change only the lines needed.

STARTTotal ← 0INPUT Number Number = -1?Total ← Total + Number OUTPUTTotalSTOP YesNo
Fig. 1: a flowchart that totals numbers until -1 is entered
Section 01

Precision matters.

Examiners can only award marks for statements a computer could follow. Compare these two versions of the same step.

Not acceptableAcceptable
if the score is bigger than the targetIF Score > Target
add the price onTotal ← Total + Price
keep asking until it is rightREPEAT ... UNTIL Guess = Secret
print the answerOUTPUT "Total cost: ", Total
Examiner trap

Describing the algorithm in English sentences earns little or nothing. Write statements: INPUT, OUTPUT, ←, IF, loops.

Section 02

Writing a solution.

Run the standard methods programs in the lab, then see how the same patterns combine into one full answer to a scenario.

DECLARE Tickets, Customer, TotalTickets, FourCount : INTEGER
DECLARE Takings : REAL
CONSTANT Price ← 5.50
TotalTickets ← 0
FourCount ← 0
FOR Customer ← 1 TO 30
    REPEAT
        OUTPUT "Number of tickets (1 to 4)"
        INPUT Tickets
        IF Tickets < 1 OR Tickets > 4
          THEN
            OUTPUT "Invalid: enter a whole number from 1 to 4"
        ENDIF
    UNTIL Tickets >= 1 AND Tickets <= 4
    TotalTickets ← TotalTickets + Tickets
    IF Tickets = 4
      THEN
        FourCount ← FourCount + 1
    ENDIF
NEXT Customer
Takings ← TotalTickets * Price
OUTPUT "Total money taken: $", Takings
OUTPUT "Customers who bought 4 tickets: ", FourCount
Worked example A ticket scenario
Each of 30 customers buys 1 to 4 concert tickets at $5.50 each. Write an algorithm that validates each input, then outputs the total money taken and the number of customers who bought 4 tickets.
  1. Initialise: TotalTickets ← 0 and FourCount ← 0 before any loop; declare the constant Price.
  2. Count-controlled loop for the 30 customers: FOR Customer ← 1 TO 30 ... NEXT Customer.
  3. Inside it, validate with a REPEAT loop: prompt, INPUT Tickets, error message if Tickets < 1 OR Tickets > 4, UNTIL the value is valid.
  4. Total the tickets and count the customers who bought 4; after the loop calculate Takings ← TotalTickets * Price and output both results.
Answer: The full pseudocode is shown above
Examiner trap

Put the validation loop inside the customer loop, around the INPUT. Validating once before the main loop checks only the first customer.

Stage 1 · Learn

Check what the sim just showed you

Four quick checks. Each correct answer earns XP and records this skill on your profile.

Quick check+10 XP

Which statement is precise enough for an exam algorithm?

Quick check+10 XP

What should come immediately before an INPUT statement in a well-written algorithm?

Quick check+10 XP

In the flowchart in Fig. 1, which symbol holds Number = -1?

Quick check+10 XP

In the ticket algorithm, why is the REPEAT loop inside the FOR loop?

Section 03

From flowchart to code, and amending.

Fig. 1 is a flowchart; the first program below is the same algorithm in pseudocode. The second program amends it to also output the average, changing only what is needed.

// the flowchart in Fig. 1
Total ← 0
INPUT Number
WHILE Number <> -1 DO
    Total ← Total + Number
    INPUT Number
ENDWHILE
OUTPUT Total
// amended: also count the numbers and output the average
Total ← 0
Count ← 0
INPUT Number
WHILE Number <> -1 DO
    Total ← Total + Number
    Count ← Count + 1
    INPUT Number
ENDWHILE
OUTPUT Total
IF Count > 0
  THEN
    OUTPUT "Average: ", Total / Count
ENDIF
Your turn
With the inputs 8, 3, 7, -1, what does the amended algorithm output?
Your turn
Why does the amended version check Count > 0 before working out the average?
Examiner trap

When amending, keep the original identifiers and structure. Adding a whole new loop, or renaming variables, risks breaking the parts that already worked.

Stage 2 · Exam

Exam-style questions

Unlocks once the four checks above are done. Worth more XP, written to IGCSE Paper 1 standard.

Finish the four checks above to unlock the exam questions
Exam style+20 XP

Which loop is the best choice to process exactly 25 exam scores?

Exam style+20 XP

With the inputs 10, 20, -1, what does the amended algorithm output for the average?

Exam style+20 XP

An algorithm must be amended to also output the smallest value input. Which pair of changes is needed?

Exam style+20 XP

Which is a correct Cambridge pseudocode constant declaration?

Skill unlocked

Writing algorithms, mastered.

This skill is now recorded on your profile. Keep the chain going.

-Rank -Level -Score -Topics
Go deeper · practice
Six original Cambridge-style questions
Writing algorithms for scenarios, converting flowcharts to pseudocode, and amending given algorithms.