baitas
asked on
cin seems to be bypassed
I am a begginer, so please be gentle on me if I made a stupid mistake!!!
here is the code:
int opcao, idade;
char nome[100], num_bi[10];
ListaPessoas lista1;
do
{
system("CLS");
cout << endl << endl;
// here lies a lot of cout, to draw a menu on the console, I left in only the first and the last
cout << "######################### ########## #######" << endl << endl;
// get the user input and pass it to the switch
cin >> opcao;
switch(opcao)
{
case(1):
{
cout << "Nome?" << endl;
cin.getline(nome,100);
cout << "Num. BI?" << endl;
cin.getline(num_bi,10);
cout <<"Idade?" << endl;
cin >> idade;
lista1.adicionar(nome, num_bi, idade);
system("PAUSE"); //added for debbuging adicionar for now only lists its parameters
}
}
}
while (opcao != 5);
and here is the question:
the first cin.getline is bypassed, it runs as if that line did not exist, I can break on it with the debbuger, but it did not help...
Am I missing something obvious, or not so obvious?
The code inside the switch used to run as expected beforeI added the switch for the menu....
One detail, this is in fact for a school assignement, so I can not use strings :(
here is the code:
int opcao, idade;
char nome[100], num_bi[10];
ListaPessoas lista1;
do
{
system("CLS");
cout << endl << endl;
// here lies a lot of cout, to draw a menu on the console, I left in only the first and the last
cout << "#########################
// get the user input and pass it to the switch
cin >> opcao;
switch(opcao)
{
case(1):
{
cout << "Nome?" << endl;
cin.getline(nome,100);
cout << "Num. BI?" << endl;
cin.getline(num_bi,10);
cout <<"Idade?" << endl;
cin >> idade;
lista1.adicionar(nome, num_bi, idade);
system("PAUSE"); //added for debbuging adicionar for now only lists its parameters
}
}
}
while (opcao != 5);
and here is the question:
the first cin.getline is bypassed, it runs as if that line did not exist, I can break on it with the debbuger, but it did not help...
Am I missing something obvious, or not so obvious?
The code inside the switch used to run as expected beforeI added the switch for the menu....
One detail, this is in fact for a school assignement, so I can not use strings :(
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Obious problem for someone experienced, almost impossible for a newbie!!!!
Thank you!!!
Thank you!!!
https://www.experts-exchange.com/questions/21015317/Input-problems-in-menu-program.html