Error when using function - pointers

I'm sure this is an easy fix, but I've been working on this for a while and nothing's coming to mind right now, but when I try to run the program, there is an error in lines 22 and 39 saying "Use of undeclared identifier 'find_function'". I'm pretty sure that I need to pass it as a pointer or something, but I don't remember exactly how to do that. Thanks for the help. I love you cplusplus.com people.
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
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>

using namespace std;

void display_vector(vector<string> restaurants){
    for (int x = 0; x != restaurants.size() - 1; x++){
        cout << restaurants[x] << ", ";
    }
    cout << restaurants.back() << endl;
}

void option_2(vector<string> restaurants){
    cout << "Enter name of restaurant to add to vector: ";
    string new_restaurant;
    cin.clear();
    cin.ignore();
    getline(cin, new_restaurant);
    find_function(new_restaurant, restaurants);
    int position;
    if (position != -1){
        restaurants.push_back(new_restaurant);
        cout << new_restaurant << " was added to the vector in index # "<< position;
    } else {
        cout << "That restaurant is already in the vector. No changes have been made.";
    }
    display_vector(restaurants);
}

void option_3(vector<string> restaurants){
    cout << "Enter name of restaurant to remove from vector: ";
    string restaurant_to_remove;
    cin.clear();
    cin.ignore();
    getline(cin, restaurant_to_remove);
    find_function(restaurant_to_remove, restaurants);
    int position;
    if (position != - 1){
        restaurants.erase(restaurants.begin() + position);
        cout << restaurant_to_remove << " was removed from the vector.";
    } else {
        cout << restaurant_to_remove << " was not found in the vector.";
    }
}

void cin_fail(string output){
    cin.clear();
    cin.ignore(1000, '\n');
    cout << output;
}

int find_function(string element_in_vector, vector<string>& restaurants){
    if (find(restaurants.begin(), restaurants.end(), element_in_vector) != restaurants.end()){
        return -1;
    } else {
        int position = find(restaurants.begin(), restaurants.end(), element_in_vector) - restaurants.begin();
        return position;
    }
}


int main(){
    bool repeat_menu = true;
    vector<string> restaurants;
    restaurants.push_back("Chick-Fil-A");
    restaurants.push_back("Applebee's");
    restaurants.push_back("McDonald's");
    restaurants.push_back("Taco Bell");
    restaurants.push_back("Bubba Gumps");
    restaurants.push_back("Zaxby's");
    restaurants.push_back("Domino's");
    restaurants.push_back("Panda Express");
    while (repeat_menu == true){
        cout << "\t\t\t\t***MENU***\nPlease select one of the following options:\n1 - Display all restaurants\n2 - Add a restaurant\n3 - Remove a restaurant\n4 - Shuffle the vector\n5 - Begin the tournament\n6 - Quit the program\n";
        int option_choice;
        cin >> option_choice;
        if (option_choice == 1){
            display_vector(restaurants);
            cout << endl;
        } else if (option_choice == 2){
            option_2(restaurants);
        } else if (option_choice == 3){
            
        } else if (option_choice == 4){
            
        } else if (option_choice == 5){
            
        } else if (option_choice == 6){
            cout << "Goodbye!";
            repeat_menu = false;
        } else {
            if (cin.fail()){
                cin_fail("Invalid selection. Please enter an integer 1-6 to select one of the options.\n\n");
            } else {
            
            }
        }
    }
    return 0;
}
Last edited on
http://www.cplusplus.com/doc/tutorial/functions/ (Declaring functions)

write int find_function(string element_in_vector, vector<string>& restaurants); in line 8
Topic archived. No new replies allowed.