How can I modify the state machine logic?

I'm working on this RTOS-based application for a vending machine controller with C and a state machine approach that manages various vending machine states as Idle,CoinInserted, SelectionMade & Dispensing, but
I'm encountering an error message in the console: StateMachine Error: Invalid transition from CoinInserted to Dispensing. This occurs when a user inserts enough coins to trigger dispensing, but the selection hasn't been confirmed yet.
typedef enum {
  STATE_IDLE,
  STATE_COIN_INSERTED,
  STATE_SELECTION_MADE,
  STATE_DISPENSING
} VendingMachineState;

typedef struct {
  VendingMachineState currentState;
} VendingMachine;

extern VendingMachineState GetCurrentState(VendingMachine *machine);
extern void SetNextState(VendingMachine *machine, VendingMachineState nextState);

How can I modify the state machine logic to prevent this invalid transition and ensure a valid sequence of states Idle -> CoinInserted -> SelectionMade -> Dispensing ?
Was this page helpful?