Check repeated elements in a vector

Hi, I've been self-studying c++ for about a month and I'm reading "Programming: Principles and Practice Using C++", I am at the end of chapter 4 and I've learnt some conditional statements, loops, functions and vectors and now I have come across this exercise:
---------- Write a program where you first enter a set of name·and·value pairs,
such as Joe 17 and Barbara 22. For each pair, add the name to a vector
called names and the number to a vector called scores (in corresponding
positions, so that if names[7]=="Joe" then scores[7]==17). Terminate
input by the line No more ("more" will make the attempt to read another
integer fail ). Check that each name is unique and terminate with an error
message if a name is entered twice. Write out all the (name,score) pairs,
one per line.
----------
So I have done the easy part but can't think of a way to solve the part it asks to terminate with an error if a name is entered twice.
I know that there are functions out there that can easily solve this but the book has not covered them yet, so how am I suppose to do this with what I have already learnt ? is this book asking me to research about solutions that it has not taught yet or I need to read these 4 chapters again ?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
#include <vector>

int main()
{
    std::vector<std::string> all_names;
    std::vector<int> all_scores;
    std::string names;
    int scores;

    std::cout<<"Please enter a name followed by it's score\n";
    while(std::cin>>names>>scores && names!="No more"){

        all_names.push_back(names);
        all_scores.push_back(scores);
    }
    for(int i=0; i<all_names.size(); ++i){
        std::cout<<all_names[i]<<'\t'<<all_scores[i]<<'\n';
    }
}

It can be done with what you've already learned. Though keep in mind that that particular book does occasionally expect you to do some independent digging to find solutions.

Before pushing the name and scores inside the while loop, insert another loop that will run through the current vectors and check if the entered name already exists. If it exists, display error message. If it doesn't, push the new values onto vectors.
Thanks Esslercuffi for replying,
I'm confused now, will I not lose the data if they are not pushed right after the input ? I mean before pushing them the vector has no elements.
I have tried to run through the current vectors after pushing them, like all_names[i] == all_names[i-1] but they are only good if the repeated names are next each other or if we sort them which in this case is not possible. I have tried all sort of things but can't find the way to check elements one by one with all the other elements within a for loop.
the data will be stored in the 'names' and 'scores' variables until you overwrite them with new values the next time through the while loop. so within the while loop, you could add another loop. Something like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
    while(std::cin>>names>>scores && names!="No more"){
        bool valid = true;
        for( int i = 0; i < all_names.size(); i++ )
        {
            if( all_names[i] == names )
            {
                valid = false;
            }
        }
        if( valid )
        {
            all_names.push_back(names);
            all_scores.push_back(scores);
        }
        else
        {
            cout << "\nduplicate name";
        }
    }
Interesting... got it! Thanks mate....
Topic archived. No new replies allowed.