check if array element value already existed when user input

Im a beginner to C++. Its my first year in college. Im completely stuck at this.I have to make a program which takes input 4 strings then check if some value already exists if it does then output value exists and thats it, if not, if they all are unique(all 4 strings) then output them in ascending order.Code bellow works and it already outputs them in ascending order, but how to find if values repeats before writing them?

sorry for my bad English guys i hope u understand what I am trying to say here
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
    string name[4];
string temp;
for(int i=0;i<4;i++){
    cout<<"Enter "<<i+1<<" string"<<endl;
    getline(cin,name[i]);
}



for(int i=0;i<4;i++){
        for(int j=i+1;j<4;j++){
            if(name[i]>name[j]){
            temp=name[i];
            name[i]=name[j];
            name[j]=temp; }

        }
    }

for(int i=0; i<4; i++)
{
   
            cout<<name[i]<< " ";
            
        

    

}
Are you allowed to use std::set? It would make this problem very simple.

You should check for duplicates as you insert into the array. If you have to wait for the user to finish inputting before outputting the duplicates, you can make note of them separately for later.
Topic archived. No new replies allowed.