Link to home
Start Free TrialLog in
Avatar of baitas
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 :(
ASKER CERTIFIED SOLUTION
Avatar of Jaime Olivares
Jaime Olivares
Flag of Peru image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of baitas
baitas

ASKER

Obious problem for someone experienced, almost impossible for a newbie!!!!

Thank you!!!