Skip to main content

Algorithm (With Loop)

The algorithm can be made to work repeatedly by enclosing it within a loop as follows:

Begin

Display 'Enter miles at start of hire: '
Get StartMiles

Loop while StartMiles is not equal to 0

Display 'Enter miles at end of hire: '
Get StopMiles

Calc TotalMiles as StopMiles - StartMiles
Calc StandardCharge as TotalMiles * 0.20
Calc Surcharge as (TotalMiles DIV 1000) * 25
Calc TotalCharge as StandardCharge + Surcharge

Display 'The total cost of the hire is ' , TotalCharge

Display 'Enter miles at start of hire (0 to exit): '
Get StartMiles

EndLoop { While }

End

If you can get the program to work once after translating the initial algorithm without the loop, then adding a loop to make it work many times is normally quite straightforward.

Make things easy for yourself: code the program at its simplest and leave the loop until later.

Next: Algorithm/Coding Layout