Skip to content

Instantly share code, notes, and snippets.

@parastuffs
Last active November 30, 2018 14:38
Show Gist options
  • Save parastuffs/a1bf5284542a777f7f27fc810fc48701 to your computer and use it in GitHub Desktop.
Save parastuffs/a1bf5284542a777f7f27fc810fc48701 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
int main(void){
int etat = 1;
bool a = false;
bool b = false;
bool alarm = false;
bool door = false;
while(true){
if (etat == 1){
printf("Inside state 1\n");
alarm = false;
door = false;
if ((!a && b) || (a&&b)){
etat = 5;
}
else if (a && !b){
etat = 2;
}
}
else if (etat == 2){
alarm = false;
door = false;
if ((!a && b) || (a&&b)){
etat = 5;
}
else if (!a &&!b){
etat = 3;
}
}
else if (etat == 3){
alarm = false;
door = false;
if ((a&&b) || (a&&!b)){
etat = 5;
}
else if (!a||b){
etat = 4;
}
}
else if (etat == 4){
alarm = false;
door = true;
if ((a&&b)||(a&&!0)){
etat = 5;
}
else if (!a&&!b){
etat = 1;
}
printf("open");
}
else if (etat == 5){
alarm = true;
door = false;
printf("bip");
}
printf("etat : %i, a : %i, b : %i\n", etat, (int)a, (int)b);
printf("a? : ");
int tmp;
scanf("%i", &tmp);
a = tmp;
printf("b? : ");
scanf("%i", &tmp);
b = tmp;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment