Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

cin seems to be bypassed

Posted on 2004-10-02
3
Medium Priority
?
355 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 2000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
Suggested Courses

609 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