Writing algorithms in pseudocode and flowcharts
Paper 2 asks you to write algorithms for short problems, in pseudocode or as a flowchart. The marks go on the logic being right and complete, not on perfect syntax, so a clear plan matters more than clever code.
Plan before you write
- Inputs: what does the algorithm need to be told?
- Processes: what has to be worked out, checked or repeated?
- Outputs: what must it show at the end, and with what message?
- Check every bullet point in the question, because each one is usually worth a mark.
Flowchart symbols
- Terminator (rounded rectangle): START and STOP.
- Input/output (parallelogram): INPUT and OUTPUT.
- Process (rectangle): a calculation or assignment.
- Decision (diamond): a question with Yes and No paths.
- Flow lines with arrows join the symbols in order. A loop is drawn as a line going back to an earlier symbol.
A short example
This algorithm reads an age and says whether a person can have a youth pass, which is for ages 11 to 18 inclusive. It rejects anything outside 0 to 120 first.
OUTPUT "Enter your age"
INPUT Age
WHILE Age < 0 OR Age > 120 DO
OUTPUT "Enter a real age"
INPUT Age
ENDWHILE
IF Age >= 11 AND Age <= 18 THEN
OUTPUT "You can have a youth pass"
ELSE
OUTPUT "You can't have a youth pass"
ENDIFWhere marks go
- Missing one of the question’s bullet points, such as a final output.
- Using an IF where the problem needs a loop, for example to keep asking until an input is valid.
- Forgetting to set a total or count before a loop.
- Outputting a value without a message when the question asks for one.
- In a flowchart, leaving a decision with only one labelled path.
Try a question
3 MARKS · MARKED ON THIS PAGEA student bus pass is only available to people aged 11 to 18 inclusive. Write an algorithm in pseudocode that: - inputs a whole number into the variable Age - while Age is less than 11 or greater than 18, outputs the message Re-enter and inputs Age again - once a valid age has been entered, outputs the message Accepted Output only these messages, with no other text.
solutionPseudocode
Loading...
Type your answer first.