Arrays, classes, and functions?

For a project I'm making a text-based game. I want to have an inventory system in which the player use or drop items. If the player uses an item, it should give them more health and/or strength. My items are kept in a class so I can keep track of the names and effects of each item. However, I'm having trouble getting the code right. Right now I have this:
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
//inventory functions
void item::effectPlayer(item& inventory[item& inventorySpot])
{
    health = health+inventory[inventorySpot].healthAdd;
    strength = strength+inventory[inventorySpot].strengthAdd; 
    inventory[inventorySpot]=blank;
}
void item::displayInventory(item& inventory)
{
    system("cls");
    while(choice != 6)
    {
        cout<<"Inventory";
        cout<<"\n1.)"<<inventory[0].itemName;
        cout<<"\n2.)"<<inventory[1].itemName;
        cout<<"\n3.)"<<inventory[2].itemName;
        cout<<"\n4.)"<<inventory[3].itemName;
        cout<<"\n5.)"<<inventory[4].itemName;
        cout<<"\n\n6.)Back";
        cin>>choice;
        selection = choice;
        switch(choice)
        {
                case 6: break;
                default: cout<<inventory[choice].itemName<<endl;
                cout<<inventory[choice].description<<endl;
                if(inventory[selection] != blank)
                {
                                cout<<"1.)Use item"<<setw(20)<<"2.)Drop item"<<setw(20)<<"3.)Back"<<endl;
                }
                else
                {
                                cout<<"3.) Back";
                }
                cin>>choice;
                choiceCheck();
                switch(choice)
                {
                                case 1: 
                                effectPlayer(inventory[selection]);
                                inventory[selection] = blank;
                                break;
                                
                                case 2: inventory[selection] = blank;
                                cout<<"\nItem has been dropped.";
                                break;
                                
                                case 3:break;
                }
                                
        }
    }
}


The class that function is in is in the header file here:
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
//item.h
#ifndef item_h
#define item_h

#include "player.h"
#include "npc.h"
#include "main.h"

#include<iostream>
#include<fstream>
#include<string>
#include<iomanip>
#include<cstdlib>
using namespace std;

class item
{
    public:
        string itemName;
        int healthAdd;
        int strengthAdd;
        int inventorySpot;
        string description;
        
    void effectPlayer(item& inventory[item& inventorySpot]);
    void displayInventory(item& inventory);
};
#endif 


And my objects for my item class are declared at the top like this:

 
item candy, vitamins, energyBar, alienFood, blank, inventory[5]={energyBar, blank, blank, blank, blank};


The 'blank' object is a place holder, I don't know if theres a better way to handle that.

Both "choice" and "selection" are declared globally.

It looks super messy, I know. I've tried combining some amalgamation of what I've been able to learn from other forum posts, but after a certain point I really needed to ask about my issue specifically. Any help is appreciated. Need this figured out ASAP
Is this all of your code?


can you try uploading everything (source files like npc.h,main.h, etc) to github?


I'm actually interested in looking at it.


For your question though, I'm afraid I'm not sure how to help without the rest of the code, though someone else might be able to if you really dont wanna upload the other files somewhere,
Topic archived. No new replies allowed.