Array Problem

Look at the following code. When it gets to the second switch (enter amount part) I run into a problem. When I input item type 1 or item type 3 it works fine. When I try item type 2, it outputs a huge random number. Item types 4 - 10 crash the computer. Help?

- Timmah \m/

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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#include <iostream>
#include <conio.h>
#include <cstdlib>
#include <string>
#include <windows.h>

using namespace std;

int main()
{
    
    char b, d;
    char item_type;
    int s;
    int amount;
    int inventory[10]; 
    
    loop15:                                                                   // shop loop
    cout << "\n\n1)General Store          5)Bar";
    cout << "\n2)Blacksmith             6)Joe's House";
    cout << "\n3)Potions/Magic Shop";
    cout << "\n4)Weapons";
    s = getch();               // goes into stores/back to menu of stores to purchase items
      switch (s) {
             case '1':
                  cout << "\n\nWelcome To The General store!\n";
                  cout << "1) 1 Gallon Water:" << endl; 
                  cout << "2) 1 lb Meat:" << endl;
                  cout << "3) 5 lbs Meat:" << endl;
                  cout << "4) Assortment of Spices/Herbs:" << endl;
                  cout << "5) Wool Gloves:" << endl;
                  cout << "6) Wool Coat:" << endl;
                  cout << "7) Light Leather Boots:" << endl;
                  cout << "8) Pack of 5 Torches:" << endl;
                  cout << "9) Pack of 5 Lanterns:" << endl;
                  cout << "10) 1 Quart of Oil:" << endl << endl; 
                  loop16:
                  cout << "Press 1 - 10 and Then Enter To Purachase An Item. Press 'b' To Go Back To The \nShop List. When done, press 'd'";
                  cin >> item_type;
                  switch (item_type) {
                         case '1':
                         case '2':
                         case '3':
                         case '4':
                         case '5':
                         case '6':
                         case '7':
                         case '8':
                         case '9':
                         case '10':
                         {
                              cout << "Enter amount: ";
                              cin >> amount;
                              inventory[item_type]+=amount;
                              cout << "Type " << item_type << " has " << inventory[item_type] << " items in it\n\n";
                              goto loop16;                        
                              }
                              break;
                         case 'b':
                              goto loop15;
                              break;
                         case 'd':
                              goto game;
                              break;
                         default:
                              {
                              cout << "Incorrect Command!";
                              goto loop16;
                              }         
                         }
                  
                  
             case '2':
                  cout << "\n\nWelcome To The Blacksmith!\n";
                  cout << "1) Hard Leather Gloves:" << endl; 
                  cout << "2) Hard Leather Boots:" << endl;
                  cout << "3) Hard Leather Torso:" << endl;
                  cout << "4) Chain Mail Helment:" << endl;
                  cout << "5) Chain Mail Torso:" << endl;
                  cout << "6) Chain Mail Pants:" << endl;
                  cout << "7) Plate Mail Helment:" << endl;
                  cout << "8) Plate Mail Torso:" << endl;
                  cout << "9) Plate Mail Pants:" << endl;
                  s = getch();
                    if (s=='b')
                    goto loop15;
                  break;
             case '3':
                  cout << "\n\nWelcome To The Potions and Magic Shop!\n"; 
                  cout << "1) Healing Potion:" << endl; 
                  cout << "2) Strength Potion:" << endl;
                  cout << "3) Poision:" << endl;
                  cout << "4) Dexterity Potion:" << endl;
                  cout << "5) Charisma Potion:" << endl;
                  cout << "6) Antidote Potion:" << endl;
                  cout << "7) Book of Fire:" << endl;
                  cout << "8) Book of Darkness:" << endl;
                  cout << "9) Book of Summons:" << endl;
                  cout << "10 Book of Healing:" << endl;
                  cout << "11) Mana Potion:" << endl;
                  cout << "12) Staff of Epicness:" << endl; 
                  s = getch();
                    if (s=='b')
                    goto loop15;
                  break;
             case '4':
                  cout << "\nweapons";
                  s = getch();
                    if (s=='b')
                    goto loop15;
                  break;
             case '5':
                  cout << "\nbar";
                  s = getch();
                    if (s=='b')
                    goto loop15;
                  break;
             case '6':
                  cout << "\njoe's house";
                  s = getch();
                    if (s=='b')
                    goto loop15;
                  break;
             default:
                  {
                  cout << "\n\nIncorrect Command!";
                  goto loop15;        
                  }
             }    
    
    game:
         cout << "GAME!";
    
    system("PAUSE");
    return EXIT_SUCCESS;
}


Please don't post duplicates.
http://www.cplusplus.com/forum/general/38826/
Topic archived. No new replies allowed.