troubleshooting Question

Getline problem - Borland C++

Avatar of koneill99
koneill99 asked on
4 Comments1 Solution959 ViewsLast Modified:
I have a strange problem.  The following code snippet demonstrates the problem.
I have 4 pieces of data I need to capture which I then store into the index of some arrays.  The index corresponds to the "loop number".

The problem is that on the FIRST LOOP, the program falls through the first GETLINE without waiting for input.  It displays "EnterStudent Name" then immediately displays "Enter student ID" (the second element).

After the ForNEXT loop goes throught the first iteration, it works properly.

It's almost like the default delimiter is being reached on the first pass without typing anything.

Any help would be appreciated.

void readData (string studentName [], string studentId [], float score [],
               int limit, const int MAX_SIZE)
        string id;
        string name;
        const int highest = 100;
        const int lowest = 0;
        int temp = 0, validGrade = 0;

        for(int i = 0; i < limit; i++)
                cout << "Enter the students name: ";
                getline(cin,name);   <========================Problem Here on 1st loop.  Program doesnt stop here on first pass
                studentName[i] = name;

                cout << "Enter " << studentName[i] << "'s i.d: ";
                studentId[i] = id;

                cout << "Enter " << studentName[i] << "'s grade: ";
                cin >> temp;
                validGrade = validateData(temp, highest, lowest);
                score[i] = validGrade;


Join our community to see this answer!
Unlock 1 Answer and 4 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros