Switch statement & if statement issue

I am writing a choose your own adventure sort of thing. My code is included below. Since there is a lot of narrative in this game, I cut out the storyline bits so it would be easier/quicker for you to read. Here is my issue:

In the function event2, I want the player to make one initial choice. If they choose choice 3, then and only then do they have yet another choice to make. My issue is, no matter which initial choice they make (1, 2, or 3) the player will still be prompted to make the special choice-3-only decision. I don't want this to happen. Any ideas as to why that is happening and how I could go about fixing it?

Thanks so much in advance.

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
#include <iostream>
using namespace std;
// HALLWAYS GAME-- Hill

int tolerance = 10;
int input;
int input2;

void printTolerance()
{
    cout << "\n(((You have " << tolerance << " remaining)))" << endl;
}

void event1()
{
    cout << "Narrative..."

    cout << "Do you raise your hand? \n1. Keep your hand down for now. \n2. Raise your hand." << endl;
    cin >> input;

    switch(input)
    {
    case 1:
        cout << "Consequence of choice 1.";

        tolerance = tolerance - 2;
        break;
    case 2:
        cout << "Consequence of choice 2.";

        tolerance = tolerance - 1;
        break;
    }
}

void event2()
{
    cout << "Narrative...";

    cout << "What do you say? \n1. \"XXXX\" \n2. \"XXXX\" \n3. \"XXXX\"" << endl;
    cin >> input;

    switch(input)
    {
    case 1:
        cout << "Consequence of choice 1";

        tolerance = tolerance - 3;

    case 2:
        cout << "Consequence of choice 2";

        tolerance = tolerance - 2;

    case 3:
        cout << "Consequence of choice 3.";

        tolerance = tolerance - 4;
    }
        if(input == 3) {
        cout << "\n\n1. \"Option 1" \n2. Option 2\n\n" << endl;
        cin >> input2;
            if(input2 == 1)
            {
                cout << "Consequence of your choice.";
                tolerance = tolerance - 1;
            }
            if(input2 == 2) {
                cout << "Consequence of other choice." << endl;
                tolerance = tolerance - 0; // Tolerance stays the same.
            }
        }

}


int main()
{
    event1();
    printTolerance();
    event2();
    printTolerance();

    return 0;
}
 
You forgot to break;
I would put the second choice within the switch statement under case 3.

Also, you don't have to type tolerance = tolerance - x;. tolerance -= x; does the same thing.
Last edited on
Oh, thanks so much!
Topic archived. No new replies allowed.