Published by Patrick Mutisya · 14 days ago
Students will be able to write clear and structured pseudocode that explicitly shows the three fundamental stages of an algorithm: input, process and output.
INPUT, OUTPUT, IF, ELSE, FOR, WHILE.# or //.A complete algorithm can be divided into three sections, as shown in the table below.
| Section | Purpose | Typical Keywords |
|---|---|---|
| Input | Obtain data from the user or another system. | INPUT, READ |
| Process | Perform calculations, decisions and loops. | IF, FOR, WHILE, SET, CALCULATE |
| Output | Present the result to the user or another system. | OUTPUT, DISPLAY, PRINT |
This example demonstrates a simple algorithm that reads a temperature in Celsius, converts it to Fahrenheit, and displays the result.
# Algorithm: Celsius to FahrenheitINPUT celsius
SET fahrenheit ← (9/5) * celsius + 32
OUTPUT fahrenheit
Explanation:
INPUT celsius – reads a numeric value from the user.SET fahrenheit ← (9/5) * celsius + 32 – the process step using the conversion formula \$F = \frac{9}{5}C + 32\$.OUTPUT fahrenheit – displays the converted temperature.This algorithm shows the use of conditional statements within the process section.
# Algorithm: Maximum of three numbersINPUT a, b, c
SET max ← a
IF b > max THEN
SET max ← b
ENDIF
IF c > max THEN
SET max ← c
ENDIF
OUTPUT max
Key points:
INPUT line gathers three separate values.SET max ← a initializes the process.IF statements compare the remaining numbers with the current max.OUTPUT max presents the largest value.Students should produce pseudocode that:
hoursWorked × hourlyRate.Suggested solution (students should attempt before viewing):
# Algorithm: Payroll CalculatorINPUT name, hoursWorked, hourlyRate
SET grossPay ← hoursWorked * hourlyRate
IF grossPay > 500 THEN
SET netPay ← grossPay * 0.80 # 20% tax deduction
ELSE
SET netPay ← grossPay
ENDIF
OUTPUT name, netPay
INPUT or OUTPUT statements – the algorithm becomes incomplete.Every well‑structured algorithm should clearly separate the three stages:
Following this pattern makes translation to actual code straightforward and improves readability.