Using #define and grabbing the information with a certain input

With what I have so far, how would I code as to ask the user to input the the name of an item and output the resulting information stored.
Ex.
Enter Card's Name: "Ancient of Lore"
Name: Ancient of Lore
Mana: 7
Attack: 5
Health: 5
Has Taunt: False

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
#ifndef Druid_Class
#define Druid_Class


#define Druid_Minions

#ifndef Ancient_of_Lore
#define	Ancient_of_Lore_Name		"Ancient of Lore"
#define	Ancient_of_Lore_Mana		7
#define	Ancient_of_Lore_Attack		5
#define	Ancient_of_Lore_Health		5
#define	Ancient_of_Lore_Taunt		false
#endif

#ifndef Ancient_of_War		
#define	Ancient_of_War_Name		"Ancient of War"
#define	Ancient_of_War_Mana		7
#define	Ancient_of_War_Attack		5
#define	Ancient_of_War_Health		5
#define	Ancient_of_War_Taunt		false
#endif

#ifndef	Cenarius			
#define	Cenarius_Name			"Cenarius"
#define	Cenarius_Mana			9
#define	Cenarius_Attack			5
#define	Cenarius_Health			8
#define	Cenarius_Taunt_Taunt		false
#endif

#ifndef	Druid_of_the_Claw									
#define	Druid_of_the_Claw_Name		"Druid of the Claw"};
#define	Druid_of_the_Claw_Mana		5
#define	Druid_of_the_Claw_Attack	4
#define	Druid_of_the_Claw_Health	4
#define	Druid_of_the_Claw_Taunt		false
#endif

#ifndef	Ironbark_Protector			
#define	Ironbark_Protector_Name		"Ironbark Protector"
#define	Ironbark_Protector_Mana		8
#define	Ironbark_Protector_Attack	8
#define	Ironbark_Protector_Health	8
#define	Ironbark_Protector_Taunt	true
#endif

#ifndef	Keeper_of_the_Grove	
#define	Keeper_of_the_Grove_Name	"Keeper of the Grove"
#define	Keeper_of_the_Grove_Mana	4
#define	Keeper_of_the_Grove_Attack	2
#define	Keeper_of_the_Grove_Health	4
#define	Keeper_of_the_Grove_Taunt	false
#endif 
1) Not possible.
2) Use classes.
Can't do using defines without writing the most tedious code ever. If you want your program to have that capability, however, it certainly is possible. You'd have to create an array of either struct or class objects, initialize the information, and then search through for what the user is looking for. A snippet would look like such:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
//declare/define struct
struct cards {
    string name;
    int mana, attack, health;
    bool taunt;
} cards_array[total_cards];

int main (void)
{
    /*Ask user for input */

    //search
    for (int i = 0; i < total_cards; i++)
    {
        if (user_input == cards_array[i].name) {
            /* output data */
        }
    }
}


Far more efficient code in the long run.
Last edited on
I have this
1
2
3
4
5
struct Minions {
    char Name;
    int Mana, Attack, Health;
    bool Taunt;
}


How would I put this information into it
1
2
3
4
5
Name				"Ancient of Lore"
Mana				7
Attack				5
Health				5
Taunt				false


http://www.cplusplus.com/doc/tutorial/structures/
I found this, but i'm not quite sure how to implement it.
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
//Fixed your struct, needed name to be a string and forgot the ending semicolon
struct Minions {
    std::string Name;
    int Mana, Attack, Health;
    bool Taunt;
};

Minions ancientOfLore;
ancientOfLore.Name = "Ancient of Lore";
ancientOfLore.Mana = 7;
ancientOfLore.Attack = 5;
ancientOfLore.Health = 5;
ancientOfLore.Taunt = false;
Last edited on
Thanks so much(: It's hard getting past the first steps for me, but once I do I get rolling real fast.
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
#include <iostream>
#include <string.h>



using namespace std;


struct Minions {
    std::string Name;
    int Mana, Attack, Health;
    bool Taunt;
};

Minions AncientofLore;
AncientofLore.Name = "Ancient of Lore";
AncientofLore.Mana = 7;
AncientofLore.Attack = 5;
AncientofLore.Health = 5;
AncientofLore.Taunt = false;

Minions AncientofWar;
AncientofWar.Name = "Ancient of War";
AncientofWar.Mana = 7;
AncientofWar.Attack = 5;
AncientofWar.Health = 5;
AncientofWar.Taunt = false;

Minions Cenarius;
Cenarius.Name = "Cenarius";
Cenarius.Mana = 9;
Cenarius.Attack = 5;
Cenarius.Health = 8;
Cenarius.Taunt = false;

Minions DruidoftheClaw;
DruidoftheClaw.Name = "Druid of the Claw";
DruidoftheClaw.Mana = 5;
DruidoftheClaw.Attack = 4;
DruidoftheClaw.Health = 4;
DruidoftheClaw.Taunt = false;

Minions IronbarkProtector;
IronbarkProtector.Name = "Ironbark Protector";
IronbarkProtector.Mana = 8;
IronbarkProtector.Attack = 8;
IronbarkProtector.Health = 8;
IronbarkProtector.Taunt = true;

Minions KeeperoftheGrove;
KeeperoftheGrove.Name = "Keeper of the Grove";
KeeperoftheGrove.Mana = 4;
KeeperoftheGrove.Attack = 2;
KeeperoftheGrove.Health = 4;
KeeperoftheGrove.Taunt = false;


Everything seems to work, but i get an error: this declaration has no storage. I'm lost on what to do next
Well, you need to stick that all that in a valid place. Start with putting everything (except the struct definition) in the main() function.
Topic archived. No new replies allowed.