Switch statement breaking code

have a dictionary program that loads a txt file into a vector then searches based on user input and returns the word, type and definition.

The search doesn't have to be fancy so its just a comparison.

The problem I am having is when I put my function and the code into the switch statement it wont function and immediately returns 0 or whatever number I have determined to return. It does this before the function executes and that means I cant ever execute.

Is this something to do with the switch statement?

see below code
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
  int searchForWord(vector <Word>& Dictonary, const string  searchWord) {

    for (Word word : Dictonary) 
    {
        
        if (searchWord == word.DictonaryWord )
        {   
            cout << "Word has been found " << endl;
            // This line assigns the type to the value and finds in map and then points to second value of key pair

            string value = DiffTypes.find(word.Type)->second;

            cout << word.DictonaryWord << ' ';

            cout << value << endl;

            cout << word.Definition << endl;
            return 1 ; 
            
           
            
           
        }
        
       
     

        
    }
    return 0; 
   
   
}



it then gets called in this switch statement
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
do
    {
        cout <<
            "\n       Welcome to the Dictionary\n"
            "----------------------------------------------------\n"
            "     Please select an option from the below menu:\n"
            "----------------------------------------------------\n"
            "\n1. Enter a word to search\n"
            "2. Find words with a specified number of characters  \n"

            "3. List all words that have a q without a following u\n"
            "4. Quit\n" << endl;


        cout << "Please select an option: " << endl;
        cin >> menuChoice;



        switch (menuChoice)
        {
        case 1:
        


            cout << "Please enter a word to search: \n";
            getline(cin, searchWord);
            searchForWord(Dictonary, searchWord);


            if (searchForWord(Dictonary,searchWord)==0) {

                cout << " word not found" << endl;
                break;
            }






        

        break;


If I move this block out of the switch it works as intended and can search as needed.
No, it's everything to do with mixing >> and getline.

https://www.tutorialspoint.com/what-is-the-use-of-cin-ignore-in-cplusplus
omg wow I had no idea.. thanks for that it works as intended.
Topic archived. No new replies allowed.