• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 360
  • Last Modified:

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 :(
0
baitas
Asked:
baitas
  • 2
1 Solution
 
Jaime OlivaresCommented:
Try with:
         cin >> opcao;
         cin.ignore();
         switch(opcao)
          {
               //etcetera
0
 
Jaime OlivaresCommented:
0
 
baitasAuthor Commented:
Obious problem for someone experienced, almost impossible for a newbie!!!!

Thank you!!!
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now