vector iteration

I made up some code for vector iteration but it is not what I wanted. From the example below, I would like to iterate through vector that is populated by inputs from user, and then get outputs for matching strings from the user with the element from arrays. In the code below that would look like:
Pizza has this ingredients that you have: ...
Pasta has this ingredients that you have:...
Pizza and pasta don't have this ingredients:...

I don't know how to do it to get only one output for each if case in one sentence like that.
What I also don't know is how to remove element from vector if it has already the same one in it.
Like for example if user has already put ingredient ham, and then written it again, to remove the new second ham element from the vector.

Thank you!
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
48
49
50
51
52
53
54
#include <iostream>
#include <vector>
using namespace std;

int main()
{
    string pizza[3]= {"ham", "tomato", "chees"};
    string pasta[3]= {"tomato", "ketchup", "olive"};
    vector<string> ingredients;
    string ingredient;
    string answer;
    string yes;
    yes=="yes";

    cout << "Do you have any ingredient, yes or no? " << flush;
    cin >> answer;

    while (answer == "yes")
    {
        cout << "Enter ingredient: " <<flush ;
        cin >> ingredient;

        ingredients.push_back (ingredient);

        cout << "More ingredients, yes or no? " << flush;
        cin >> answer;
    }
        for (vector<string>::iterator   i = ingredients.begin();
                                        i!= ingredients.end();
                                        ++i)
    {
        cout << "You have: "<<endl;
        cout << *i << endl;
    }
for (vector<string>::iterator   i = ingredients.begin();
                                        i!= ingredients.end();
                                        ++i)
        {if ((*i==pizza[0]) || (*i==pizza[1]) || (*i==pizza[2]))
        {
            cout<<"Pizza has this ingredients: " << *i <<endl;
        }
        else if ((*i==pasta[0]) || (*i==pasta[1]) || (*i==pasta[2]))
        {
            cout<<"Pasta has this ingredients: " << *i <<endl;
        }
        else
        {
            cout<< *i <<"are not in pizza or pasta.";
        }



        }
}
Last edited on
Topic archived. No new replies allowed.