0% found this document useful (0 votes)
8 views

Assignment3 (State Machine)

The document describes a state machine program with 5 states. The program allows the user to choose a state and prints which state they are in. It uses switch statements to call functions for each state.

Uploaded by

numanshafi2728
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Assignment3 (State Machine)

The document describes a state machine program with 5 states. The program allows the user to choose a state and prints which state they are in. It uses switch statements to call functions for each state.

Uploaded by

numanshafi2728
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include <stdio.

h>
#include <stdint.h>
#include <string.h>
void state_01();
void state_02();
void state_03();
void state_04();
void state_05();
int main()
{
int choose;
int currentState=0;
int previousState=0;
while(1){
printf("Enter which state you want to go\n");
scanf("%d",&choose);
currentState=choose;
if(previousState==1)
{
printf("Welcome\n");
}
switch(choose)
{
case 1:
state_01();
previousState=1;
break;
case 2:
state_02();
previousState=2;
break;
case 3:
state_03();
previousState=3;
break;
case 4:
state_04();
previousState=4;
break;
case 5:
state_05();
previousState=5;
break;
}
}
}
void state_01()
{
printf("You are in state 01 of this Machine\n");
}
void state_02()
{
printf("You are in state 02 of this Machine\n");
}
void state_03()
{
printf("You are in state 03 of this Machine\n");
}
void state_04()
{
printf("You are in state 04 of this Machine\n");
}
void state_05()
{
printf("You are in state 05 of this Machine\n");
}

You might also like