Complete the code to define the initial state of the state machine.
enum State { INIT, RUNNING, ERROR };
State currentState = [1];The initial state is usually set to INIT to start the state machine properly.
Complete the code to transition from INIT to RUNNING state.
if (currentState == INIT) { currentState = [1]; }
After initialization, the state machine moves to the RUNNING state to perform its main tasks.
Fix the error in the switch statement to handle the ERROR state.
switch (currentState) {
case INIT:
// initialization code
break;
case RUNNING:
// running code
break;
case [1]:
// error handling code
break;
default:
break;
}The ERROR state must be handled explicitly in the switch to manage error conditions.
Fill both blanks to check if the state machine is in RUNNING state and then set it to ERROR.
if (currentState == [1]) { currentState = [2]; }
This code checks if the machine is RUNNING and sets it to ERROR if a problem occurs.
Fill all three blanks to create a dictionary that maps states to their string names.
const char* stateNames[] = { [1], [2], [3] };This array holds the string names for each state in order: INIT, RUNNING, ERROR.