getline being skipped after first time through loop.

I'm really new to all of this, so bear with me.

The first time the program goes through the for loop, everything is fine. But the second time, it prints the "Please enter the employee's name:" cout, skips the getline and goes directly to the "Please enter the employee's ID number:". The getline for the ID number works fine every time. What am I doing wrong here? I'm so confused.

(also, I know I'm not using the dataOut at all yet. that's coming later. I'm trying to build this step by step for a project)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
void collectData ()
{
     ofstream dataOut;
     dataOut.open ("EricInputData.txt");
     string NAMEID[10][2];
     double EVAL[10][4];
     int lengthName, lengthID;
     
     cout << "Welcome to the Employee Data Entry Program." << endl;
     for (int m=0; m<10; m++)
     {
         cout << "Please enter the employee's name: ";
         getline(cin, NAMEID[m][0]);
         lengthName = NAMEID[m][0].length();
         while (lengthName >= 50)
         {
          cout << "Invalid entry.";
          cout << "\nLast name must be under 50 characters.";
          cout << "\nPlease re-enter the employee's last name: ";
          getline(cin, NAMEID[m][0]);
          lengthName = NAMEID[m][0].length();
         } 
         cout << "Please enter the employee's ID number: ";
         getline(cin, NAMEID[m][1]);
         lengthID = NAMEID[m][1].length();
         while (lengthID != 6)
         {
          cout << "That is not a six digit ID number." << endl;
          cout << "Please enter the employee's ID number: ";
          getline (cin, NAMEID[m][1]);
          lengthID = NAMEID[m][1].length();
         }
         cout << "Please enter the employee's" << endl;
         cout << "Fall semester evaluation:    ";
         cin >> EVAL[m][0];
         cout << "Spring semester evaluation:  ";
         cin >> EVAL[m][1];
         cout << "Summer semester evaluation:  ";
         cin >> EVAL[m][2];
         cout << "Annual comprehensive:        ";
         cin >> EVAL[m][3]; 
     }

     dataOut.close ();
}
Ok, I put this above the employee name getline:
cin.ignore(1000, '\n');

but now it makes me hit a key to start up the process (just once, the first time). Is there a way to resolve my issue without having to do that?
Put your cin.ignore(1000, '\n'), or just a cin.get(), AFTER every getline to eat up the carrage return.
Last edited on
Topic archived. No new replies allowed.