This section examines how to take a problem, decompose it and design an algorithm to solve it.
The following example has been taken from an AQA past paper. It reflects the type of question that may appear in an exam paper.
A programmer has been asked to design a program that calculates an estimate of the braking distance in metres for a new model of go-kart that is travelling between 10 and 50 kilometres per hour - km/h.
The program should keep asking the user to enter a speed for the go-kart until they enter a speed between 10 and 50 km/h. The breaking distance in metres is calculated by dividing the speed by 5. The user should then be asked if the ground is wet and the breaking distance should be multiplied by 1.5 if this is true. Finally, the program should output the calculated braking distance.
The first step is to break down - decompose - the overall problem into several smaller, more easily solved problems:
From the above, the solution will require the following variables. These values will change as the program is run.
*As user input is used here, a string is valid as they may answer yes/no.
The following constants will be used. These values will not change when the program is run.