SEARCHING THROUGH VECTOR AND RETURNING IF WORD IS FOUND!!

Can someone fix my code !! I need help with searching through my vector for a word and return it as found

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
111
112
113
114
115
116
117
  #include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <algorithm>
#include <iterator>
#include <sstream>
#include <conio.h>
#include <cstring>
#include <cstdlib>
#include <ctime>

using namespace std;


int searchVector(vector<string> QueryArray, string value){
for (int i = 0; i < QueryArray.size(); ++i)
    if (QueryArray[i] == value)
    return i;
return -1;



}


int main()
{
    string line;
    vector<string> QueryArray;

    ifstream myfile("colleges.txt");
    if(!myfile) //Always test the file open.
    {

        cout << "  Error opening  " << endl;
        system("pause");
        return 1;

    }
        while (getline(myfile,line))
    {
            QueryArray.push_back(line);
    }
    cout << QueryArray[4564] << endl;

    int Colleges;
                cout << "Welcome to My College and University summary program" << endl;

cout << "Press 1 to enter possible colleges and universities and the program will tell you if they appear on the list  " << endl;
cout << "Press 2 to find out how many colleges or universities appear in the state of your choice" << endl;
cout << "Press 3 to find out how many colleges and universities appear in our list in total" << endl;

cout << "Press 4 to quit" << endl;

cin >> Colleges;

if (Colleges == 1)
{
string search_word;

cout << "What University would you like to find?" << endl;
cin >> search_word;

getline(cin, search_word);
       if (std::find(QueryArray.begin(), QueryArray.end(), search_word)!= QueryArray.end())
{
return true;

return false;
        cout << "The word was found*** this part is not working properly***" << search_word <<  endl; }
else {
        cout << "---------The Matrix not found*** its not finding the words correctly*** ------------   " << endl;
}
}
else if (Colleges == 2)
{

 {
  string line2;
    int SIZE = 4564;
    string STATE[SIZE];
  ifstream file2 ("states.txt");
  if (file2.is_open())
  {
      int i = 0;
    while (file2 >> line2 )
    {
        STATE[i] = line2;
            i++;
    }
        file2.close();
  }
  else cout << "Unable to open file";
}

   const int numStates = 4564;
    string STATES[numStates];

    //find out the number of any particular state in the array
    cout << "Enter a state's abbreviation:" << endl;
    string userState;
    cin >> userState;
    int stateCount = 0;
    for(int i = 0; i < numStates; i++){
        if(STATES[i] == userState)
            {
            stateCount++;
        }
    }
    cout << userState << " has " << stateCount << " colleges." << endl;
}
else
   cout << "There are 4564 Universities available to pick from!" << endl;
    return 0;
}
Please don't multiple post. On line 68 you have a return, and on line 70 you have a return. Perhaps that is your problem.
Topic archived. No new replies allowed.