Removing items from an inventory!

I have finally got inventory and items to work. I just now need to know how to remove an item from the inventory. If you could please help me by editing the code below that would be nice. I have spent 2 day just trying to find out how to remove the item from the inventory and have given up so if you can please help me find out how to remove the item from inventory.

I have marked where i want the remove option to be. :)

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
#include <cstdlib>
#include <iostream>
#include <string>
#include <iostream.h>
#include <memory>
#include <istream>
using namespace std;
using std::cout;
using std::cin;
using std::endl;
using std::string;
int main()
{

const int MAX_ITEMS = 10;
string inventory[MAX_ITEMS];
int choice, choice2, choice3, choice4, numItems = 0;

for(;;)

    {
    cout << "--------------------------------------------------------------------------------\n";
    cout << "Welcome to Kroz!\n";
    cout << "Please report and bugs to Jon_p3rron@hotmail.com. Thanks :)\n";
    cout << "IMPORTANT: There is currently a glitch when having a choice option. If you enter and letters the code will begin to spam uncontrolably. If this haapens you will have to restart the game. Thanks for understanding! :)\n\n"; 
    system("pause");
    cout << "Krow v1.0 08/09/2011 Alpha Version (incomplete)\n\n";
    cout << "--------------------------------------------------------------------------------\n";
    system("pause");
    cout <<"\n\n";
    cout << "Would you like to play?\n";
    cout << "1 - Yes!\n";
    cout << "2 - No.\n";
    
    
    string name;
    cout << "Choice:";
    cin>> choice;
    switch (choice)
    
                {
           case 1:
                
                cout << "Well good luck and have fun!\n";                
                cout << "Please enter your name:";
                cin >> name; 
                cout << "\n\n";
                cout << "Hello, " << name << " and welcome to Kroz! I am your guide through this game and can be as a guide for new players and for old players. But first of as your guide I have to state what version of the game your on: Kroz 1.0 08/09/2011. This game has frequent updates and should be checked back on every once and a while for a update! :) But other than that I say... Good luck!\n\n";
                cout << "Your in the middle of a street. Destruction all around you, deserted cars and stores, you find your self in a small town, your not really sure where. All the buidlings around you have shattered windows and rusted doors. It appears there hasn't been anyone around for a long time.\n\n";
                system("pause");
                cout << "\n\n";
                cout << "So when you get a small description like this you get 4 choices: go North, East, South or West. You can try each choice if you want, you can always go back the direction you came unless there is something blocking your route back.\n\n";
                loop3:
                loop2:
                cout << "1-North\n";
                cout << "2-East\n";
                cout << "3-South\n";
                cout << "4-West\n";
                cout << "Choice:";
                cin>> choice2;
                switch (choice2)
                                {
                                case 1:
                                     cout << "Hmm... It appears you cannot go this way.\n\n";
                                     goto loop2;
                                     break;
                                case 2:
                                     cout << "There is an abandined store. Would you like to explore it?\n\n";
                                     cout << "1-Yes!\n";
                                     cout << "2-No.\n";
                                     cout << "Choice:";   
                                     cin>> choice3;
                                     switch (choice3)  
                                            {
                                            case 1:
                                                 cout << "Most of the shelves in the store are empty. You check behind the cashiers counter and oddly find something...\n";
                                                 system("pause");
                                                 cout << "You found a key!\n";
                                                 inventory[numItems++] ="Key";
                                                 cout << "You head back to the street.\n\n";
                                                 cout << "Your items:\n";
                                                 for (int i = 0; i < numItems; ++i)
                                                 cout << inventory [i] << endl;
                                                 goto loop3;
                                                 break;
                                            case 2:
                                                 cout << "You decide not to go in as it is to frightening.\n\n";
                                                 goto loop3;
                                                 break;
                                            default:
                                                    cout << "I'm sorry, that option isn't available.\n\n";
                                                    goto loop3;
                                                    }
                                     break;
                                case 3:
                                     cout << "You head farther down the road.\n\n";
                                     break;
                                case 4:
                                     cout << "There is an abandoned house. Would you like to explore it?\n\n";
                                     cout << "1-Yes!\n";
                                     cout << "2-No.\n";
                                     cout << "Choice:";   
                                     cin>> choice4;
                                     switch (choice4)  
                                            {
                                                       case 1:
                                                            cout << "The door is locked.\n";
//player uses the key here and it becomes removed from their inventory HERE HERE HERE! The player already has the key and needs to use it! (take it out of the inventory. I do not want to put the key back in the inventory.
                                                            }                    
                                     break;
                                default:
                                        cout << "I'm sorry, that option isn't available.\n\n";
                                        goto loop2;
                                }              
                break;  
                
           case 2:
                cout << "Aww... Well maybe some other time?\n\n\n";
                system("pause");
                return 0;
                break;
           default:
                cout << "\n\nI'm sorry, that option isn't available.\n";
               
                }                    
    }  
         system("pause");
         return 0;
}


Thanks for all the help in advance! :)

EDIT: If you compile and run it makes more sense.
Last edited on
I'm writing this message on my mobile phone. So i can't compile it.

First, you should use vector instead of array.
Vectors have many useful methods like erase. And easily you can remove item from a vector(inventory).
1) Don't use system()
2) Don't use goto, it's not required here
3) Your program design is not going to work, even with this little amount of code, it is already incredibly hard to read and very messy. I suggest you learn some OOP; it'll help you make it a lot simpler and easier to understand.
Well just so you guys know, I'm self teaching myself... so you would recommend being actually taught by a professional?
Topic archived. No new replies allowed.