Help with switch

Hi im new to programming and the forum. :)

I'm creating a text game in C++/ C using just cout, cin, switch etc as I dont want to over do it on my first go..

I was trying to make a switch within a switch.

I got the switch to work okay, but case two from the first switch carries over after selecting an option from the switch in case one.

I've add "break" but this does not seem to work.

I did read on google about adding a "goto" statement but read alot of bad feedback on them.

Its probably something really simple...

Hope someone can 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

cout <<" Select 1 - To bowl\n";
cout <<" Select 2 - Walk away\n";
int pGame;
    cout <<"Select 1 or 2: ";
    cin >>pGame;
    
    switch (pGame)
    {
         case 1:
           cout <<" Select 1 - Throw normal\n";
           cout <<" Select 2 - Trick shot\n";
           int throwBall;
           cout <<"Select 1 or 2: ";
           cin >>throwBall;
    
    switch (throwBall)
    {
           case 1:
                cout <<"normal throw text etc etc\n";
                break;
           case 2:
                cout <<"trick shot etc etc etc\n";
                break;
           default:
                   cout <<"Error - Invalid input; only 1 or 2 allowed.\n";
    }

                
           case 2:
                cout <<"You play it safe and walk away, but with the heavy burden of knowing you could have made the shot and got a perfect game" << endl;
                break;
           default:
                   cout <<"Error - Invalid input; only 1 or 2 allowed.\n";
    
    }
You don't have a break at the end of case 1 in the outer switch.
Opps!

I just added a break and it worked like a charm :)

Thank you very much abramus
Topic archived. No new replies allowed.