Solved

cin seems to be bypassed

Posted on 2004-10-02
3
332 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

707 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

16 Experts available now in Live!

Get 1:1 Help Now