Repeat until Flashcards
1
Q
A free drinks machine provides 20 different drinks.
The machine has a small keypad with keys 0-9, Submit and Cancel. It has a
small LCD display, which can display messages to the user.
To get a drink the user selects it by typing in the relevant number (1-20). If
they type in the wrong number, they can cancel and enter a new number.
When they are happy with their choice they press the submit button. If the
selection is valid (1-20) and the drink available, the machine will dispense
the drink.
Write an algorithm in pseudocode which for the process outlined above
A
Choice = “” REPEAT INPUT Button IF Button is between 0 and 9 THEN Choice = Choice & Button OUTPUT Choice ELSE IF Button = CANCEL THEN Choice = “” END IF UNTIL Button = OK IF Choice is between 1 and 20 THEN IF drink chosen available THEN Dispense drink OUTPUT “Collect your drink” ELSE OUTPUT “Drink not available” END IF ELSE OUTPUT “Invalid selection” END IF Wait OUTPUT “Ready”