A part of one of the programs in my assignment requires to declare three arrays of same size which will be used in parallel to store gpa's, registration numbers and names of the students respectively. When I use a single loop to take input in all these three arrays then a strange thing happens. It takes input normally in the gpa and registration number arrays but simply skips the input of the name (a string) and go directly to the next loop. However, if I comment out the other prompts and input lines from this loop and use it to take input solely in the array of names then it works fine.
Please tell me what could be the reason of this problem.
Here is the code that I am using.
#include <iostream>
#include <string>
using namespace std;
int main()
{
const int size = 3;
float Gpa[size];
unsigned int Reg[size];
string Name[size];
for (int i=0; i<size; i++)
{
cout << "Enter Registration number of the student no. " << i+1 << ": ";
cin >> Reg[i];
cout << "Enter GPA of student no. " << i+1 << ": ";
cin >> Gpa[i];
cout << "Enter Name of the sudent no. " << i+1 << ": ";
getline(cin, Name[i]);
}
system("pause");
return 0;
}
and here is sample run of this program: