UP | HOME

HW23
COP-3223H

Submit your answer via webcourses

In this exercise, we will create a state machine (on paper, not implemented in C) that recognizes whether a vending machine has received proper change. There are 5 (nickel), 10 (dime), and 25 (quarter) cent coins, and the item costs 45 cents. If the user provides 45 cents or more, then accept the change and stop. While the user is entering coins, there is one state for every possible combination of coins, i.e., 5 cents, 10 cents, etc., until 45 cents. For instance, if the user provides 3 nickels or 1 nickel and 1 dime, the machine will be in a state corresponding to seeing 15 cents.

In a table, list all possible states and what the next state is for every new coin entered? Some of entires have been filled out. Fill out the rest of the state changes for dime and quarter.

The first column is the state. Then the remaining columns are the coins that can be input. For each row, look at the current state and see how each coin changes the state. For instance, if we are in state 1, which represents having seen 5 cents, and the user enters a dime, that transitions the machine to state 3, which represents 15 cents. If we are in state 0, which represents having seen 0 cents, and the user enters a quarter, than transitions the machine to state 5, which represents 25 cents.

State Nickel Dime Quarter
0 (0 cents) 1 2 5
1 (5 cents) 2 3  
2 (10 cents) 3    
3 (15 cents)      
4 (20 cents)      
5 (25 cents)      
6 (30 cents)      
7 (35 cents) 8    
8 (40 cents) 9    
9 (45 or more cents) 9    

Author: Paul Gazzillo

Created: 2026-03-11 Wed 14:14

Validate