Grade Book Using Vectors

I'm still in my first C++ class and I'm stuck on my current homework. I have to program a simple grade book using vectors to store the student name & grades. So far, I can enter a name & 18 grades, but I can't get it to prompt for additional student names. I'm also a bit lost on how to retrieve the information once I have it in there. Right now, I'd be happy with a hint on how to enter more than one name with an associated set of grades.
Also....I'm not entirely sure the entered name is even associated with the grades. How do I know if I've connected the name vector and the grade set vector?
Thank you in advance!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
  #include <iostream>
#include <vector>
#include <iomanip>
#include <string>
using namespace std;

void getGrade () {
    const int numGrades = 18;
    int countGrade;
    vector<float> grades(numGrades);
    
    for (countGrade = 0; countGrade <numGrades; countGrade++) {
        cout << "Enter grade "<<(countGrade+1) << ": ";
        cin >> grades[countGrade];
    }
 
    
    
}

void getNameGrade () {
    
    const int numStude = 30;
    int countName;
    vector<string> studeName(numStude);
    
    cout << "Please enter the student's name in the following format: first_last: ";
    for (countName=0; countName<=numStude; countName++){
        cin >> studeName[countName];
        cout << "Please enter the grades for ";
        cout << studeName[countName] << ": ";
        getGrade();
    }
    
    
    
  
    
}

int main() {
   
    getNameGrade();
    
    
}
The first thing that comes to mind when connecting the two is to use a struct or class that has both those elements in them and making one vector of that struct or class type.

That being said, how are you going to use this information? As soon as the getGrade function exits on line 19, that vector you just populated no longer exists because it goes out of scope. Same for all the studeNames you get on line 39. They all are destroyed at the end of the function.
Topic archived. No new replies allowed.