Problem with getting variables to work in other code


Hello im kind of new with class' and im wondering how i can get the data to work in other parts of my program, i have some few errors where i define it and it doesnt work,and other areas dont work
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#include <iostream>
#include <ctime>
#include <string>
#include <sstream>
#include <cstdlib>
using namespace std;
void pause(int dur);//pauses the program for a set number of seconds
class Monster
{
      public:
      // constructor
      Monster(){}
      ~Monster(){}
      //Memeber Methods      
      void DisplayStats()
      {
           cout << "\n\n\t--------Monster Stats--------";
           cout << "\n\tYou sent out a " << Type << " type.\n";
           cout << "\n\tAttack:" << Attack;
           cout << "\n\tDefense:" << Defense;
           cout << "\n\tHealth:" << Health;
           cout << "\n\tAdvantage:" << Advantage;
           cout << "\n\tDisadvantage:" << Health;
           cout << "\n\t-------------------------------\n\t";
      } 
      //Accessor Methods
      string GetType() { return Type; }
      void SetType(string x) { Type = x; }
      
      int GetAttack() { return Attack; }
      void SetAttack(int x) { Attack = x; }
      
      int GetDefense() { return Defense; }
      void SetDefense(int x) { Defense = x; }
      
      int GetHealth() { return Health; }
      void SetHealth(int x) { Health = x; }
      
      string GetAdvantage() { return Advantage; }
      void SetAdvantage(string x) { Advantage = x; }
      
      string GetDisadvantage() { return Disadvantage; }
      void SetDisadvantage(string x) { Disadvantage = x; }
      
      string GetMonsterName() { return MonsterName; }
      void SetMonsterName(string x) { MonsterName = x; }
      
      private:
      string Type;
      int Attack;
      int Defense;
      int Health;
      string Advantage;
      string Disadvantage;
      string MonsterName;
};

void YourFireType()
{
Monster * YourFireType = new Monster;
Type = YourFireType->SetType("fire");
Attack = YourFireType->SetAttack(8);
Defense = YourFireType->SetDefense(1);
Health = YourFireType->SetHealth(40);
Advantage = YourFireType->SetAdvantage("Nature");
Disadvantage = YourFireType->SetDisadvantage("Water");
Name = YourFireType->SetMonsterName("YourFireType");
system("PAUSE");
return Type;
return Attack;
return Defense;
return Health;
return Advantage;
return Disadvantage;
return Name;
}

void OpponentWaterType()
{
Monster * OpponentWaterType = new Monster;
OType = OpponentWaterType->SetType("fire");
OAttack = OpponentWaterType->SetAttack(8);
ODefense = OpponentWaterType->SetDefense(1);
OHealth = OpponentWaterType->SetHealth(40);
OAdvantage = OpponentWaterType->SetAdvantage("Nature");
ODisadvantage = OpponentWaterType->SetDisadvantage("Water");
OName = OpponentWaterType->SetMonsterName("YourFireType");
system("PAUSE");
return OType;
return OAttack;
return ODefense;
return OHealth;
return OAdvantage;
return ODisadvantage;
return OName;
}

int TypeAdvantages()
{
//Fire vs Fire
     if(Type == "fire" && OType == "Fire") 
     { 
     Attack = Attack + 0;
     OAttack = OAttack + 0;
     } 
//Fire vs Water
     if(Type == "fire" && OType== "Water") 
     { 
     Attack = Attack / 2;
     OAttack = OAttack * 2;
     }
//Fire vs Nature
     if(Type == "fire" && OType == "Nature")
     { 
     Attack = Attack * 2;
     OAttack = OAttack / 2;
     }
//Water vs Fire
     if(Type == "water" && OType == "Fire") 
     { 
     Attack = Attack * 2;
     OAttack = OAttack / 2; 
     } 
//Water vs Water
     if(Type == "water" && OType == "Water") 
     { 
     Attack = Attack + 0;
     OAttack = OAttack + 0;
     }
//Water vs Nature
     if(Type== "water" && OType== "Nature")
     { 
     Attack = Attack / 2;
     OAttack = OAttack * 2;
     }
//Nature vs Fire
     if(Type == "nature" && OType == "Fire") 
     { 
     Attack = Attack / 2;
     OAttack = OAttack * 2; 
     } 
//Nature vs Water
     if(Type == "nature" && OType == "Water") 
     { 
     Attack = Attack * 2;
     OAttack = OAttack /2;
     }
//Nature vs Nature
     if (Type == "nature" && OType == "Nature")
     { 
     Attack = Attack + 0;
     OAttack = OAttack + 0;
     }
     return Attack;
     return OAttack;
}
Last edited on
can you post your errors?
Errors
62 C:\Dev-Cpp\Untitled10.cpp `Type' undeclared (first use this function)
63 C:\Dev-Cpp\Untitled10.cpp `Attack' undeclared (first use this function)
64 C:\Dev-Cpp\Untitled10.cpp `Health' undeclared (first use this function)
65 C:\Dev-Cpp\Untitled10.cpp `Advantage' undeclared (first use this function)
66 C:\Dev-Cpp\Untitled10.cpp `Disadvantage' undeclared (first use this function)
67 C:\Dev-Cpp\Untitled10.cpp `Name' undeclared (first use this function)
69 C:\Dev-Cpp\Untitled10.cpp return-statement with a value, in function returning 'void'
70 C:\Dev-Cpp\Untitled10.cpp return-statement with a value, in function returning 'void'
71 C:\Dev-Cpp\Untitled10.cpp return-statement with a value, in function returning 'void'
72 C:\Dev-Cpp\Untitled10.cpp return-statement with a value, in function returning 'void'
73 C:\Dev-Cpp\Untitled10.cpp return-statement with a value, in function returning 'void'
74 C:\Dev-Cpp\Untitled10.cpp return-statement with a value, in function returning 'void'
75 C:\Dev-Cpp\Untitled10.cpp return-statement with a value, in function returning 'void'
81 C:\Dev-Cpp\Untitled10.cpp `OType' undeclared (first use this function)
82 C:\Dev-Cpp\Untitled10.cpp `OAttack' undeclared (first use this function)
83 C:\Dev-Cpp\Untitled10.cpp `ODefense' undeclared (first use this function)
84 C:\Dev-Cpp\Untitled10.cpp `OHealth' undeclared (first use this function)
85 C:\Dev-Cpp\Untitled10.cpp `OAdvantage' undeclared (first use this function)
86 C:\Dev-Cpp\Untitled10.cpp `ODisadvantage' undeclared (first use this function)
87 C:\Dev-Cpp\Untitled10.cpp `OName' undeclared (first use this function)
89 C:\Dev-Cpp\Untitled10.cpp return-statement with a value, in function returning 'void'
90 C:\Dev-Cpp\Untitled10.cpp return-statement with a value, in function returning 'void'
91 C:\Dev-Cpp\Untitled10.cpp return-statement with a value, in function returning 'void'
92 C:\Dev-Cpp\Untitled10.cpp return-statement with a value, in function returning 'void'
93 C:\Dev-Cpp\Untitled10.cpp return-statement with a value, in function returning 'void'
94 C:\Dev-Cpp\Untitled10.cpp return-statement with a value, in function returning 'void'
95 C:\Dev-Cpp\Untitled10.cpp return-statement with a value, in function returning 'void'
101 C:\Dev-Cpp\Untitled10.cpp `Type' undeclared (first use this function)
101 C:\Dev-Cpp\Untitled10.cpp `OType' undeclared (first use this function)
103 C:\Dev-Cpp\Untitled10.cpp `Attack' undeclared (first use this function)
104 C:\Dev-Cpp\Untitled10.cpp `OAttack' undeclared (first use this function)
Last edited on
The error messages are very clear. So do not disturb the forum and read the messages and update the code. Any name used in a program shall be at first declared before its usage.
Last edited on
I thought it was, in class i declared it
Can you explain me and yourself what does this function return?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
void YourFireType()
{
Monster * YourFireType = new Monster;
Type = YourFireType->SetType("fire");
Attack = YourFireType->SetAttack(8);
Defense = YourFireType->SetDefense(1);
Health = YourFireType->SetHealth(40);
Advantage = YourFireType->SetAdvantage("Nature");
Disadvantage = YourFireType->SetDisadvantage("Water");
Name = YourFireType->SetMonsterName("YourFireType");
system("PAUSE");
return Type;
return Attack;
return Defense;
return Health;
return Advantage;
return Disadvantage;
return Name;
}
Topic archived. No new replies allowed.