teach-ict.com logo

THE education site for computer science and ICT

3. Being precise

The pseudocode on the previous page for boiling water and making tea is not very clear:

  • START
  • Fetch a tea cup
  • Boil some water
  • Place a tea bag into the cup
  • Pour on boiling water
  • Stir tea bag
  • Remove tea bag
  • END

How much water needs to be boiled? How much should be poured onto the tea bag? How long should the tea bag be stirred for? What do we do with the tea bag when it is removed?

The pseudocode can be written more precisely in order to answer these questions:

  • START
  • Fetch a tea cup
  • Add 300 ml of water to the kettle
  • Boil the water until the kettle switches itself off
  • Place a new tea bag into the bottom of the cup
  • Pour 200 ml of boiling water from the kettle, into the cup
  • Leave the tea bag to stew for 10 seconds
  • Use a metal spoon to stir the tea bag for 3 seconds
  • Using the spoon, remove the tea bag from the cup
  • Dispose of the tea bag
  • END

Note the 'START' and 'END' statements. These confirm the points where the algorithm begins and where it has been fully laid out.

You could also number each step in between, to make it easier to talk about individual lines of the algorithm, but it is not essential.

If the task of the computer programmer was to write code for controlling a tea-making robot, this extra precision is essential.

Challenge see if you can find out one extra fact on this topic that we haven't already told you

Click on this link: what is pseudocode