Beginner Coding Probs

I am beginner and i am trying to make a simple game. This code is good until the second question where it doesn't work no matter what. Please help.

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
  #include <iostream>
using namespace std;

int main(int argc, const char * argv[])
{
    int option, option2, option3;
    
    cout << "You need to escape! Choose a pathway: /n 1) Right /n 2) Left /n 3) Behind /n 4) Front" << endl;
    cin >> option;
    
    switch (option) {
        case 1:
            cout << "Wrong!" << endl;
            break;
            
        case 2:
            cout << "Wrong!" << endl;
            break;
            
        case 3:
            cout << "Wrong!" << endl;
            break;
            
        case 4:
            cout << "Right! Choose next pathway: /n 1) Right /n 2) Left /n 3) Behind /n 4) Front" << endl;
            cin >> option2;
            break;
            
            switch (option2) {
                case 1:
                    cout << "Wrong!" << endl;
                    break;
                    
                case 2:
                    cout << "Right! Choose next pathway: /n 1) Right /n 2) Left /n 3) Behind /n 4) Front" << endl;
                    cin >> option3;
                    break;
                
                case 3:
                    cout << "Wrong!" << endl;
                    break;
                    
                case 4:
                    cout << "Wrong!" << endl;
                    break;
                    
                    switch (option3) {
                        case 1:
                            cout << "Wrong!" << endl;
                            break;
                            
                        case 2:
                            cout << "Wrong!" << endl;
                            break;
                            
                        case 3:
                            cout << "Congrats! You Escaped!" << endl;
                            break;
                            
                        case 4:
                            cout << "Wrong!" << endl;
                            break;
                            
                        default:
                            cout << "Invalid Entry" << endl;
                            break;
                    
                    
            
            
            
            
                    }}}
    return 0;
}


- Your second switch statement should be placed before the break statement in line 37 as far as i know.

- Additionally, a loop would be ideal as well.

liamw309 wrote:

I am beginner and i am trying to make a simple game. This code is good until the second question where it doesn't work no matter what. Please help.

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
  #include <iostream>
using namespace std;

int main(int argc, const char * argv[])
{
    int option, option2, option3;
    
    cout << "You need to escape! Choose a pathway: /n 1) Right /n 2) Left /n 3) Behind /n 4) Front" << endl;
    cin >> option;
    
    switch (option) {
        case 1:
            cout << "Wrong!" << endl;
            break;
            
        case 2:
            cout << "Wrong!" << endl;
            break;
            
        case 3:
            cout << "Wrong!" << endl;
            break;
            
        case 4:
            cout << "Right! Choose next pathway: /n 1) Right /n 2) Left /n 3) Behind /n 4) Front" << endl;
            cin >> option2;
            break;
            
            switch (option2) {
                case 1:
                    cout << "Wrong!" << endl;
                    break;
                    
                case 2:
                    cout << "Right! Choose next pathway: /n 1) Right /n 2) Left /n 3) Behind /n 4) Front" << endl;
                    cin >> option3;
                    break;
                
                case 3:
                    cout << "Wrong!" << endl;
                    break;
                    
                case 4:
                    cout << "Wrong!" << endl;
                    break;
                    
                    switch (option3) {
                        case 1:
                            cout << "Wrong!" << endl;
                            break;
                            
                        case 2:
                            cout << "Wrong!" << endl;
                            break;
                            
                        case 3:
                            cout << "Congrats! You Escaped!" << endl;
                            break;
                            
                        case 4:
                            cout << "Wrong!" << endl;
                            break;
                            
                        default:
                            cout << "Invalid Entry" << endl;
                            break;
                    
                    
            
            
            
            
                    }}}
    return 0;
}
Topic archived. No new replies allowed.