This was an interview question to be coded in C++:
Write code for a vending machine: Start with a simple one where it just vends one type of item. So
I don't know whether that would have gotten you through the interview, but I'd personally refrain from coding any state machine by hand, especially if it's in a professional setting. State machines are a well researched problem, and there exist well tested open source tools which often produce superior code to what you will produce yourself by hand, and they also help you with diagnosing problems with your state machine by eg. being able to generate state diagrams automatically.
My goto tools for this kind of problem are: