dragon slayer [HELP]

can someone help me with this little game? im having trouble with the nested switch statements
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
 //
//  main.cpp
//  textventure
//
//  Created by Beth Stephens on 6/24/13.
//  Copyright 2013 __MyCompanyName__. All rights reserved.
//
#include <string>
#include <iostream>
using namespace std;
int main (int argc, const char * argv[])
{
    string name;
    cout << "what's your name?" << endl; 
    cin >> name;
    cout << "hello, sir " << name << "!" << endl;
    sleep(2);
    int game = 1;
    while (game == 1){
    cout << "where shall we go?" << endl;
    sleep(1);
    cout << "shop(1), arena(2), or adventure(3)?" << endl;
    int whttodo;
    cin >> whttodo;
    switch (whttodo) {
        case 1:
            cout << "what will you buy?" << endl;
            sleep(1);
            cout << "weapons?(1) defence?(2) misc?(3)" << endl;
            int shpchce;
            cin >> shpchce;
            switch (shpchce){
                case 1:
                    cout << "what will you buy?" << endl;
                    cout << "copper sword for 5 coins(1)" << endl;
                    sleep(1);
                    cout << "iron sword for 10 coins(2)" << endl;
                    sleep(1);
                    cout << "copper axe for 4 coins(3)" << endl;
                    sleep(1);
                    cout << "iron axe for 11 coins(4)" << endl;
                    sleep(1);
                    cout << "longbow for 15 coins(5)" << endl;
                    sleep(1);
                    cout << "crossbow for 23 coins(6)" << endl;
                    sleep(1);
                    cout << "fire mace for 30 coins(7)" << endl;
                    sleep(1);
                    cout << "ice nunchacku for 30 coins(8)" << endl;
                    sleep(1);
                    cout << "enchanted dragon spiral lance for 1,000,000 coins(9)" << endl;
                break;
                case 2:
                    cout << "what will you buy?" << endl;
                    sleep(1);
                    cout << "copper shield for 5 coins(1)" << endl;
                    sleep(1);
                    cout << "iron shield for 10 coins(2)" << endl;
                    sleep(1);
                    cout << "copper helmet for 4 coins(3)" << endl;
                    sleep(1);
                    cout << "iron helmet for 11 coins(4)" << endl;
                    sleep(1);
                    cout << "steel chestplate for 15 coins(5)" << endl;
                    sleep(1);
                    cout << "dolomite armorsuit for 23 coins(6)" << endl;
                    sleep(1);
                    cout << "thunder jacket for 30 coins(7)" << endl;
                    sleep(1);
                    cout << "wind forcefield for 30 coins(8)" << endl;
                    sleep(1);
                    cout << "cave peoples' arcane protector seal for 1,000,000 coins(9)" << endl;
                break;
                case 3:
                    cout << "what will you buy?" << endl;
                    sleep(1);
                    cout << "dodge wings for 20 coins(1)" << endl;
                    sleep(1);
                    cout << "healing amulet for 30 coins(2)" << endl;
                    sleep(1);
                    cout << "'cloud-in-a-jar' for 45 coins(3)" << endl;
                    sleep(1);
                    cout << "ancient rune of cascading aura for 1,000,000 coins(4)" << endl;
                break;
                default:
                    cout << "off with your head!" << endl; 
                break;
            }
            break;
        case 2:
            cout << "battle for coins!" << endl;
            break;
        case 3:
            cout << "adventure awaits!" << endl;
            break;
        default:
            cout << "off with your head!" << endl;
            break;
    }
    return 0;
    }

}
What is the problem you're having?

I can tell you that you can't declare variables inside a case statement without putting a set of braces around it; otherwise the variable might be destructed (when you hit the end of the switch) without having been constructed (because you went to a different case).
Thanks, but when I run this piece in Xcode, it breaks down after the 'shop' switch statement. I'll try your suggestion see if it works!
Topic archived. No new replies allowed.