It should also be noted, in addition to StuXYZ's excellent comments, that you should get an entire Student before adding a copy of it to the vector.
Your choice of variable names is pretty good, actually, but I will nit-pick about the vector name: "sNames" -- first, it isn't a vector of student names, it is a vector of student data, which includes the name. A good name for a collection of Student is "students".
So, remember, the order to do things is:Get all the information about a student into a single Student object.
Use push_back() to append a copy of that Student object to the vector of Students.
Repeat.
Also, I notice you have variables starting with the prefix "temp". You never use them, so get rid of them. (Delete lines 21 and 22.)
Remember, a Student is not just a name. It is a collection of information about one particular student: his first name, last name, and all his grades.
// Here is the list of students we wish to populate.
vector<Student> students;
...
// This loop gets 'numStudents' students from the user.
for (int i = 0; i < numStudents; i++) {
// This is the temporary variable we'll use to hold information
// about a single student as we get it from the user.
Student student;
// Now, gather the individual pieces until we have them all.
cout << "Enter the first name for student #" << (i + 1) << ": ";
cin >> student.fName;
cout << "Enter the last name for student #" << (i + 1) << ": ";
cin >> student.lName;
cout << "Enter the exam scores for student #" << (i + 1) << endl;
for (int j = 0; j < NUM_EXAMS; j++) {
// Just like we do for the students, this
// object represents a single exam grade.
double examScore;
// Get it from the user
cout << " Exam #" << (j + 1) << ": ";
cin >> examScore;
// We have a complete exam grade, so we append a copy
// of it to the list of exams for the current student.
student.exams.push_back( examScore );
}
// At this point, we have gathered all the information about a single student.
// Append a copy of the student's information to our list of students.
students.push_back( student );
}
Now, todisplay the student's information, you need a function that knows how to write a Student structure to the screen using cout:
void cout_Student( const Student& student ) {
// Displays the student as:
//
// Jenny Jones 98 100 89.3 95 100
//
cout << student.fName << " " << student.lName;
for (int n = 0; n < student.exams.size(); n++)
cout << " " << student.exams[ n ];
cout << endl;
// This, of course, is just an example. You can organize your
// function to display the student information however you like.
}
In your code, you can now display all the students with a simple loop:
for (int n = 0; n < students.size(); n++) {
cout_Student( students[ n ] );
}
If you are ready, you can turn that function into an overloaded insertion operator. If you don't know what that means, then worry about that later. Your professor will get there in due time.
Hope this helps.