Vector shuffling

Hey guys im pretty new to programming. I have a program that has a vector with a list of restaurants. i need to be able to shuffle the elements in the vector. I have looked it up and tried to use a random_shuffle() function but I am getting an error. Please help if you can.

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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#include <iostream>
#include<string>
#include<vector>
#include <algorithm>


using namespace std;


void option_a(vector<string>& restaurants){
    long comma = restaurants.size() - 1;
    for (int i =0; i <restaurants.size(); i++ ){
        if (i == comma){
            cout << restaurants[i]<<endl;
        }
        else {
            cout <<restaurants[i]<<", ";
        }
    }
}

vector<string> add(vector<string>& restaurants, string user_restaurant){
    restaurants.push_back(user_restaurant);
    return restaurants;
}
vector<string>remove(vector<string>& restaurants, string user_restaurant){
    for (int i=0; i<restaurants.size(); i++){
        if (restaurants[i] == user_restaurant){
            long last_pos = restaurants.size()-1;
            restaurants[i]=restaurants[last_pos];
            restaurants.pop_back();
            cout<<user_restaurant<<" has been removed"<<endl;
            cout<<endl;
        }
    }
        
    return restaurants;
}
int random (int j){
    int random_number= rand()%j;
    return random_number;
}

int main(){
    vector <string> restaurants;
    restaurants.push_back("Arbys");
    restaurants.push_back("Wendys");
    restaurants.push_back("McDonalds");
    restaurants.push_back("Red Robin");
    restaurants.push_back("Goodwood");
    restaurants.push_back("Panda Express");
    restaurants.push_back("Subway");
    restaurants.push_back("Los Hermanos");
    restaurants.push_back("The Red Iguana");
    restaurants.push_back("Burger King");
    restaurants.push_back("Big Town Hero");
    restaurants.push_back("Olive Garden");
    restaurants.push_back("Stanfords");
    restaurants.push_back("Red Lobster");
    restaurants.push_back("Sizzler");
    restaurants.push_back("Quizznos");
   
    cout<<"Option A: Display all restaurants"<<endl;
    cout<<"Option B: Add a restaurant"<<endl;
    cout<<"Option C: Remove a restaurant"<<endl;
    cout<<"Option D: Shuffle restaurants"<<endl;
    cout<<"Option E: Begin Tournement"<<endl;
    cout<<"Option F: Quite program"<<endl;
    cout<<"Choose an option:";
    string user_choice;
    cin>>user_choice;
    string user_restaurant;
    if (user_choice == "A" || user_choice=="a"){
        option_a(restaurants);
    }
    if (user_choice =="B" || user_choice=="b"){
        cout<<"Please type the name of the restaurant you would like to add:";
        cin.ignore();
        getline(cin, user_restaurant);
        if (find (restaurants.begin(), restaurants.end(), user_restaurant)!= restaurants.end()){
            cout <<"We already have that restaurant";
        }
        else {
            cout<<"Your restaurant has been added"<<endl;
            add(restaurants, user_restaurant);
            option_a(restaurants);
        }
    }
    if (user_choice == "C" || user_choice =="c"){
        cout <<"Which restaurant would you like to remove? ";
        cin.ignore();
        getline(cin, user_restaurant);
        if (find (restaurants.begin(), restaurants.end(), user_restaurant)!= restaurants.end()){
            remove(restaurants, user_restaurant);
        }
        else {
            cout << user_restaurant<<" is not on the list"<<endl;
            cout<<endl;
        }
        option_a(restaurants);
        
    }
    if (user_choice == "D" || "d"){
        random_shuffle(restaurants.begin(), restaurants.end(), random);
    }
    
    return 0;
}

Topic archived. No new replies allowed.