Login

Please fill in your details to login.





d. vending machine simulator

A coding challenge

Objective

Build a console application that simulates a vending machine using a Finite State Machine (FSM) model. This will test your ability to manage state, use modular programming, and handle logical transitions based on user input.

Requirements

1
Design your vending machine to sell a single product that costs 80p.
2
The machine must have at least four distinct states:
IDLE: Waiting for a user to start.
TAKING_COINS: Accepting coin inputs (10p, 20p, 50p) and tracking the running total.
DISPENSING: Releasing the product once 80p or more has been inserted.
CHANGE: Returning any excess money before returning to the IDLE state.
3
Use a loop to continuously run the machine, checking the current state and asking for appropriate user input.
4
Prevent the user from inserting invalid coins (e.g., rejecting a 5p or 30p coin).

Stretch Goal

Add a "cancel" command during the TAKING_COINS state. If the user types "cancel", the machine should immediately transition to a REFUND state, return all inserted coins, and then return to IDLE.

Last modified: September 6th, 2026
The Computing Café works best in landscape mode.
Rotate your device.
Dismiss Warning