al cambiar de case, deja de recibir instrucciones del teclado
Publicado por Miguel (1 intervención) el 09/10/2018 19:08:33
buenas tardes, tengo un problema con este código.
Se supone que tendría que simular un autómata pero al momento de que pasa del primer estado, deja de recibir instrucciones por el teclado.
¿alguien podría ayudarme?
Dejo una copia del código:
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<conio.h>
using namespace std;
#define e0 0
#define e1 1
#define e2 2
#define e3 3
#define e4 4
int main(){
int e=e0;
int S=0;
char c;
cout<<"-->e0 ";
while(S!=1){
switch(c){
case e0:
cin>>c;
if(c=='h'){
system("CLS");
cout<<"-->|e0| -h->|e1| ";
e=e1;
}else{
system("CLS");
cout<<"-->e0 ";
e=e0;
}
break;
case e1:
cin>>c;
if(c=='o'){
system("CLS");
cout<<"-->|e0| -h->|e1| -o->|e2| ";
e=e2;
}else{
system("CLS");
cout<<"-->e0 ";
e=e0;
}
break;
case e2:
cin>>c;
if(c=='l'){
system("CLS");
cout<<"-->|e0| -h->|e1| -o->|e2| -l->|e3| ";
e=e3;
}else{
system("CLS");
cout<<"-->e0 ";
e=e0;
}
break;
case e3:
cin>>c;
if(c=='a'){
system("CLS");
cout<<"-->|e0| -h->|e1| -o->|e2| -l->|e3| -a->|e4| "<<endl;
e=e4;
}else{
system("CLS");
cout<<"-->e0 ";
e=e0;
}
break;
case e4:
cout<<"\t\t\t hola"<<endl;
S=1;
break;
}
}
getch();
return 0;
}
Se supone que tendría que simular un autómata pero al momento de que pasa del primer estado, deja de recibir instrucciones por el teclado.
¿alguien podría ayudarme?
Dejo una copia del código:
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<conio.h>
using namespace std;
#define e0 0
#define e1 1
#define e2 2
#define e3 3
#define e4 4
int main(){
int e=e0;
int S=0;
char c;
cout<<"-->e0 ";
while(S!=1){
switch(c){
case e0:
cin>>c;
if(c=='h'){
system("CLS");
cout<<"-->|e0| -h->|e1| ";
e=e1;
}else{
system("CLS");
cout<<"-->e0 ";
e=e0;
}
break;
case e1:
cin>>c;
if(c=='o'){
system("CLS");
cout<<"-->|e0| -h->|e1| -o->|e2| ";
e=e2;
}else{
system("CLS");
cout<<"-->e0 ";
e=e0;
}
break;
case e2:
cin>>c;
if(c=='l'){
system("CLS");
cout<<"-->|e0| -h->|e1| -o->|e2| -l->|e3| ";
e=e3;
}else{
system("CLS");
cout<<"-->e0 ";
e=e0;
}
break;
case e3:
cin>>c;
if(c=='a'){
system("CLS");
cout<<"-->|e0| -h->|e1| -o->|e2| -l->|e3| -a->|e4| "<<endl;
e=e4;
}else{
system("CLS");
cout<<"-->e0 ";
e=e0;
}
break;
case e4:
cout<<"\t\t\t hola"<<endl;
S=1;
break;
}
}
getch();
return 0;
}
Valora esta pregunta


0