I want to create a menu where the user chooses the option 1 to 5, would like the user to type the number and the program would enter the option without having to press Enter .
Here's an example
#include <iostream>
#include <cstdio>
#include <string>
using namespace std;
struct pessoa {
int ID;
string nome [20];
string tel [20];
};
typedef struct pessoa P;
int main () {
int vet[10]={0,0,0,0,0,0,0,0,0,0};
int opc;
do{
cout<<"[0] incluir pessoa"<<endl;
cout<<"[1] Alterar pessoa"<<endl;
cout<<"[2] Excluir pessoa"<<endl;
cout<<"[4] Recuperar pessoa"<<endl;
cout<<"[5] Sair"<<endl;
cin>>opc;
switch (opc){
case '0':
break;
case '1':
break;
case '2':
break;
case '3':
break;
case '4':
break;
case '5':
break;
default:
cout<<"Opção Invalida"<<endl;
}
}while(opc != 5);
return 0;
}
I want to read opc
without the user having to enter Enter and automatically fall into switch-case
.