For a exercise I have to make a programm where several student puts thier home-grades in and thier names.

here's the code

#include <string>
#include <vector>
#include <iostream>

using namespace std ;

int main()

    vector<string> names ;
    typedef vector<double>::size_type siz_tp ;
    siz_tp aantal ;
    vector<double> numbers;
    typedef vector<double>::size_type siz_tp ;
    siz_tp aantal ;
    string name ;

    // ask for and read the words to count
    cout << "Enter first your name"

    while (cin >> name)
        while (name.lenght == 0)
            cout "You have not entered your name"
            cin >> name
        names.push_back (name) ;
        cout " Enter now your 5 home-grades :"
        cin >> number
        numbers.push_back (number);
        size = numbers.size () ;



But what's the best way how I can check if a student put in 5 numbers.
I can do if numbers.size = 5 but on student 2 the vector must be 10 , on student 3 14 and so on.

Anyone who have a tip ?


I don't understand what you mean by the "vector must be 10", "the vector must be 14", etc.

Can you clarify?


Hello David,

Of course I can.

Every student has 5 home-grades.
So when student 1 is ready the vector numbers has a size of 5.
When student 2 is ready the vector numbers has a size of 10

Is this clear ?


It sounds like you should make a 'student' class, something like this:

class Student
 std::vector<double> Grades; //will be length 5
 std::string Name;
 void InputGrades();

Then from the main program, you have to do something like this:

std::vector<Student> students;

while(more students)
Student currentStudent;

Good luck!



Sorry, Im not allowed to use classes.
That's in one of the next chapters.

But I could use something like

aantal = names.size() ; // size of the names so the number of students which enters her/his grades.
aantal2 = numbers.size();  // numbers of grades put in by students. 
while ( aantal 2 <> aantal *5 ) 

Can this work ?


(please remember to close you code tags with /code :) )

What is all this business you're doing with typedef and size_type? None of that should be necessary here if I've understood the problem correctly?

What does the variable name "aantal" mean?

I'm not sure what this condition is doing?

while ( aantal 2 <> aantal *5 )

Yes, you want there to be 5 times the number of grades as names, but you don't want that to be the main loop condition, right? You want the main loop condition to be how many names should be entered, no?



I closed this question.
The exercise was to put the names and grades in a vector not the numbers of each test.

Sorry for the confusion.


Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.