What if the process is difficult to see?
Sometimes a scenario makes sense, but the algorithm still feels hidden.
In this method, you carry out the task yourself using example values. Each action you perform becomes a stage in the algorithm.
Learn how to act out a programming task, identify the stages and turn those actions into an algorithm.
Sometimes a scenario makes sense, but the algorithm still feels hidden.
In this method, you carry out the task yourself using example values. Each action you perform becomes a stage in the algorithm.
The calculator must take two numbers and an operator, then output the result.
| Requirement | Run-through 1 | Run-through 2 | Step Revealed |
|---|---|---|---|
| Take the first integer. | Enter 10 | Enter 2 | INPUT Number1 |
| Take the operator. | Enter + | Enter ^ | INPUT Operator |
| Take the second integer. | Enter 20 | Enter 3 | INPUT Number2 |
| Output the result. | Output 30 | Output 8 | Check the operator, perform the calculation and output the result. |
INPUT Number1
INPUT Operator
INPUT Number2
IF Operator = "+"
THEN
Result β Number1 + Number2
ELSEIF Operator = "-"
THEN
Result β Number1 - Number2
ELSEIF Operator = "*"
THEN
Result β Number1 * Number2
ELSEIF Operator = "/"
THEN
Result β Number1 / Number2
ELSE
Result β Number1 ^ Number2
ENDIF
OUTPUT "The result is: ", ResultIdentify the inputs, processes and outputs before writing the code.
Best when: the requirements separate clearly into data, actions and results.
Carry out the task with example values and turn your actions into code.
Best when: the process or order is difficult to identify.
Why is it useful to carry out the calculator task with two different operators rather than only one?
10 + 20 = 30
This records the answer but hides the stages.
Input 10 β input + β input 20 β check operator β add values β output 30.
This reveals the algorithm.