structs help

so i am working on structures to put into a game where i have an inventory system but it is very cumbersome when adding new items into the game and its over all just ugly how it has been written. i am working on structures to completely replace it. what i would like to start with is have a simple program with a few structures that when run will display all of the items i have made. i have done this in a simple way but this is not what i want.

the part where i have cout << and all of the data from each struct works but what i want to do is just have the program know what each on is and display them without me having to write each one out.

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
#include <iostream>

using namespace std;

struct item
{
    char name[20];
    int id;
    int att;
    int def;
};

int main()
{
    item sword = 
    {
         "Sword",
         1,
         5,
         2
    };
    item dagger =
    {
         "Dagger",
         2,
         3,
         2
    };
    
    cout << sword.name << " id " << sword.id << " att " << sword.att << " def " << sword.def;
    cout << endl << endl;
    cout << dagger.name << " id " << dagger.id << " att " << dagger.att << " def " << dagger.def;
    
    cin.get();
    
    return 0;
}


from there i will be wanting to be able to have the user imput an id# and have the program tell the user everything there is to know about the item.

once there i will have no problem adding this to my game.

for example:

console: please enter item id:
user input: 1
console: sword id 1 att 5 def 2



My game can be found here if anyone is wondering:
https://sites.google.com/site/temprpgquestion/go-here-for-the-program
You need to use a function to display an object of type item.
12
13
14
void Display (const item * it)
{   cout << it->name << " id " << it->id << " att " << it->att << " def " << it->def << endl;
}


30
31
    Display (&sword);
    Display (&dagger);   
Last edited on
Thanks a lot.
Topic archived. No new replies allowed.