Extremely confused, switch bug

Alright so this whole function works fine unless an E is put through the switch statement. It will print out a blank line, then ask for input again. If you put in the E again, it works fine. It ONLY does it for THIS letter. Every other letter works like a charm. Am i missing something obvious?

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
    std::string userInput;
    char extractedInput;
    bool validChoiceMade = false;

    while ( !validChoiceMade )
    {
        std::cout << ">";

        std::getline(std::cin, userInput);
        extractedInput = toupper(userInput[0]);

        switch ( extractedInput )
        {
            case 'N': if ( world[userX][userY].get_exit(North) )
                            {
                                validChoiceMade = true;
                                userX--;
                                std::cout << world[userX][userY].get_description(North) << std::endl;
                            }
                            else
                            {
                                std::cout << "I dont think that is an option at this point." << std::endl;
                            } break;
            case 'E': if ( world[userX][userY].get_exit(East) )
                            {
                                validChoiceMade = true;
                                userY++;
                                std::cout << world[userX][userY].get_description(East) << std::endl;
                            }
                            else
                            {
                                 std::cout << "I dont think that is an option at this point." << std::endl;
                            } break;
            case 'S': if ( world[userX][userY].get_exit(South) )
                            {
                                validChoiceMade = true;
                                userX++;
                                 std::cout << "I dont think that is an option at this point." << std::endl;
                            }
                            else
                            {
                                 std::cout << "I dont think that is an option at this point." << std::endl;
                            } break;
            case 'W': if ( world[userX][userY].get_exit(West) )
                            {
                                validChoiceMade = true;
                                userY--;
                                std::cout << world[userX][userY].get_description(West) << std::endl;
                            }
                            else
                            {
                                std::cout << "I dont think that is an option at this point." << std::endl;
                            } break;
                default: std::cout << "I dont think that is an option at this point." << std::endl;
        }
    }
}
Can we see get_description()? That's most likely where the problem is.

Also, line 38 is suspicious.
Last edited on
directions are enumerated, 0 north 1 east 2 south 3 west
exitDescription is array with the appropriate string descriptions in [0][1][2][3]

1
2
3
4
std::string cboardtile::get_description(int direction)
{
    return exitDescription[direction];
}


line 38 was a mistake, i just fixed it but same error with E passing through
Last edited on
This is the output
1
2
3
4
5
6
7
[E]ast
[S]outh
>e

>e
I don't think that is an option at this point.
> 

I figured it out, it was executing fine I just have not set the exit bools yet, lol..
Topic archived. No new replies allowed.