Solved

cin seems to be bypassed

Posted on 2004-10-02
3
333 Views
Last Modified: 2010-04-01
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
Comment
Question by:baitas
  • 2
3 Comments
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 500 total points
ID: 12207018
Try with:
         cin >> opcao;
         cin.ignore();
         switch(opcao)
          {
               //etcetera
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 12207021
0
 

Author Comment

by:baitas
ID: 12207167
Obious problem for someone experienced, almost impossible for a newbie!!!!

Thank you!!!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now