string studentName;
string studentGender;
int studentCapacity;
int n =0;
cout << "Insert n:" << endl;
cin >> n;
Student* student = new Student[n];
for(int i=0;i<n;++i)
{
cout << "Enter your name:" ; //ask for name
getline(cin, studentName);
cout << endl;
cout << "Enter your Gender(Male or Female):"; //ask for gender
getline(cin, studentGender);
cout << endl;
cout << "How many roomate(s) do you wish to have?:" << endl; //ask for capacity
cout << "1. I want 1 roomate only (2 people in total)" << endl;
cout << "2. I want 2 roomate (3 people in total)" << endl;
cin >> studentCapacity;
cout << endl;
}
system("cls");
for(int i=0;i<n;++i)
{
student[i].Print(); //print student's information
}
My problem is simple yet hard to trace.
I don't know what happen the program didn't prompt me to input student name and it straightly asked me for gender.
It just appears as:
1 2
Enter your name:
Enter your gender:
only the program asked me to input my gender..
I thought the name and gender has same getline syntax?
tried using cin instead of getline for studentName,
and I added up the code as you suggested, seems working but it works like a string cin.
I try to input 'Peter Jackson' but the result displayed will be Peter only...
unable to debug getline with array, if I use cin.get(),
the program does not work, program did not prompt for any input and gave me some junk values when displaying information.
I tried to add cin.ignore() in line 13 in the code displayed, and it seems like working properly but it seems silly to put cin.ignore() inside a loop and it works quite badly if I just add it after cin my n since it only ignore once.
If I input my n is 2, my first student input is okay but for the input of second student the program, I managed to put the student name, but the program did not prompt for the gender etc etc...