I am attempting to create a student object which takes the name, id, email, and three grades which are integers.
My code is quite simple and is as follows:
studentObj* newStudent = new studentObj;
cout << "Student First Name: ";
getline(cin, newStudent->name);
cout << "Student ID: ";
getline(cin, newStudent->id);
cout << "Student Email: ";
getline(cin, newStudent->email);
cout << "Grade 1: ";
cin >> newStudent->gradeOne;
cout << "Grade 2: ";
cin >> newStudent->gradeTwo;
cout << "Term Grade: ";
cin >> newStudent->termGrade;
cout << "Student Name: " + newStudent->name << endl;
cout << "Student ID: " + newStudent->id << endl;
cout << "Student Email: " + newStudent->email << endl;
cout << "Grade 1: " + newStudent->gradeOne << endl;
cout << "Grade 2: " + newStudent->gradeTwo << endl;
I assumed this would run flawlessly, but unfortunately that is not the case. It seems to be an issue mixing the getline()
and cin
.
The output is:
Student Name: Test Tester
Student ID: abcdef
Student Email: email@test.com
rade 1:
ade 2:
m Grade:
I've tried adding cin.ignore(numeric_limits<streamsize>::max(),'\n');
in a few places, but no luck. Any suggestions?
`