Operator not working <

Hello Can you guys help me, the operators < in the following codes below are not working:

1
2
3
4
5
6
7
8
9
10
11
12
 if(Mage.HP < zero)//If Mage dies
		{
			Warrior.POW += 5;
			Warrior.HP += 3000;
			Mage.HP = 10000;
			rounds += 1;
			enemiesKilled += 1;
			cout << "You defeated Mage!" << endl;
			cout << endl;
			system("pause");
			system("cls");
		}


1
2
3
4
5
6
7
8
9
10
11
12
13
if(Assassin.HP < zero)
		{
			Warrior.AGI += 3;
			Warrior.DEX += 3;
			Warrior.HP += 3000;
			Assassin.HP = 10000;
			rounds += 1;
			enemiesKilled += 1;
			cout << "You defeated Assassin!" << endl;
			cout << endl;
			system("pause");
			system("cls");
		}


1
2
3
4
5
6
7
8
9
10
11
12
13
if(Warrior.HP < zero)
		{
			Mage.HP += 3;
			Mage.VIT += 3;
			Mage.HP += 3000;
			Warrior.HP = 10000;
			rounds += 1;
			enemiesKilled += 1;
			cout << "You defeated Warrior!" << endl;
			cout << endl;
			system("pause");
			system("cls");
		}


1
2
3
4
5
6
7
8
9
10
11
12
if(Warrior.HP < zero)
	{
		ifPlayerHPZero();
	}
	if(Mage.HP < zero)
	{
		ifPlayerHPZero();
	}
	if(Assassin.HP < zero)
	{
		ifPlayerHPZero();
	}


Here is my main cpp file:
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>

using namespace std;

 

class Unit // Unit is Warrior,Mage, and Assassin
{
public:
	int HP;
	int POW;
	int VIT;
	int AGI;
	int DEX;
};

//Variables
string answer;
int rounds;
int enemiesKilled;
int zero = 0;

//Functions
int inputInformation();
int ifPlayerHPZero();

int inputInformation()
{
	string playerName;

	//Select Class
	cout << "Select a class" << endl;
	cout << endl;
	cout << "Warrior" << endl;
	cout << "Mage" << endl;
	cout << "Assassin" << endl;
	cin >> answer;
	system("cls");

	//Input name
	cout << "Input your name" << endl;
	cin >> playerName;
	system("cls");

	if(answer == "Warrior" || answer =="warrior")
	{
		cout << "Your name is: " << playerName << endl;
		cout << endl;
		cout << "You have selected Warrior!" << endl;
		cout << endl;
		cout << "HP = 10,000" << endl;
		cout << "POW = 100" << endl;
		cout << "VIT = 500" << endl;
		cout << "AGI = 60" << endl;
		cout << "DEX = 60" << endl;
		cout << endl;
		system("pause");
		system("cls");
	}
	else if(answer == "Mage" || answer == "mage")
	{
		cout << "Your name is: " << playerName << endl;
		cout << endl;
		cout << "You have selected Mage!" << endl;
		cout << endl;
		cout << "HP = 10,000" << endl;
		cout << "POW = 100" << endl;
		cout << "VIT = 500" << endl;
		cout << "AGI = 50" << endl;
		cout << "DEX = 70" << endl;
		cout << endl;
		system("pause");
		system("cls");
	}
	else if(answer == "Assassin" || answer == "assassin")
	{
		cout << "Your name is: " << playerName << endl;
		cout << endl;
		cout << "You have selected Assassin!" << endl;
		cout << endl;
		cout << "HP = 10,000" << endl;
		cout << "POW = 100" << endl;
		cout << "VIT = 500" << endl;
		cout << "AGI = 70" << endl;
		cout << "DEX = 50" << endl;
		cout << endl;
		system("pause");
		system("cls");
	}
	return 0;

}
int ifPlayerHPZero()
{
	cout << "You died" << endl;
	cout << endl;
	cout << "Rounds finished: " << rounds << endl;
	cout << "Enemies killed: " << enemiesKilled << endl;
	cout << endl;
	system("pause");
	system("cls");
	return 0;
}

int main()
{
	inputInformation();

	srand(time(0));
	int warriorAttack = rand() % 500;
	int mageAttack = rand() % 500;
	int assassinAttack = rand() % 500;
	int r = rand() % 2;

	string warriorEnemies[] = {"Mage","Assassin"};
	string mageEnemies[] = {"Warrior","Assassin"};
	string assassinEnemies[] = {"Warrior","Mage"};
	string warriorTurn = warriorEnemies[r];
	string mageTurn = mageEnemies[r];
	string assassinTurn = assassinEnemies[r];
	
	Unit Warrior; Unit Mage; Unit Assassin;
	//Warrior
	Warrior.HP = 10000; 
	Warrior.POW = 100;
	Warrior.VIT = 500;
	Warrior.AGI = 60;
	Warrior.DEX = 60;
	//Mage
	Mage.HP = 10000;
	Mage.POW = 100;
	Mage.VIT = 500;
	Mage.AGI = 50;
	Mage.DEX = 70;
	//Assassin
	Assassin.HP = 10000;
	Assassin.POW = 100;
	Assassin.VIT = 500;
	Assassin.AGI = 70;
	Assassin.DEX = 50;

	//If player Warrior
	if(answer == "Warrior" && warriorTurn == "Mage") //Warrior VS Mage
	{
		for(int i = 0;i < 10000; i++)
		{
		Warrior.HP -= mageAttack;
		Mage.HP -= warriorAttack += 250;	

		cout << "Warrior's HP: " << Warrior.HP << endl;
		cout << "Mage's HP: " << Mage.HP << endl;
		cout << endl;
		cout << "Warrior's Damage: " << warriorAttack << endl;
		cout << "Mage's Damage: " << mageAttack << endl;
		cout << endl;
		system("pause");
		system("cls");
		}
		if(Mage.HP < zero)//If Mage dies
		{
			Warrior.POW += 5;
			Warrior.HP += 3000;
			Mage.HP = 10000;
			rounds += 1;
			enemiesKilled += 1;
			cout << "You defeated Mage!" << endl;
			cout << endl;
			system("pause");
			system("cls");
		}
	}
	else if(answer == "Warrior" && warriorTurn == "Assassin") //Warrior VS Assassin
	{
		for(int i = 0;i < 10000; i++)
		{
		Warrior.HP -= assassinAttack;
		Assassin.HP -= warriorAttack;

		cout << "Warrior's HP: " << Warrior.HP << endl;
		cout << "Assassin's HP: " << Assassin.HP << endl;
		cout << endl;
		cout << "Warrior's Damage: " << warriorAttack << endl;
		cout << "Assassin's Damage: " << assassinAttack << endl;
		cout << endl;
		system("pause");
		system("cls");
		}
		if(Assassin.HP < zero)
		{
			Warrior.AGI += 3;
			Warrior.DEX += 3;
			Warrior.HP += 3000;
			Assassin.HP = 10000;
			rounds += 1;
			enemiesKilled += 1;
			cout << "You defeated Assassin!" << endl;
			cout << endl;
			system("pause");
			system("cls");
		}
	}

	//If player Mage
	if(answer == "Mage" && mageTurn == "Warrior") //Mage VS Warrior
	{
		for(int i = 0;i < 10000; i++)
		{
		Mage.HP -= warriorAttack;
		Warrior.HP -= mageAttack;

		cout << "Mage's HP: " << Mage.HP << endl;
		cout << "Warrior's HP: " << Warrior.HP << endl;
		cout << endl;
		cout << "Mage's Damage: " << mageAttack << endl;
		cout << "Warrior's Damage: " << warriorAttack << endl;
		cout << endl;
		system("pause");
		system("cls");
		}
		if(Warrior.HP < zero)
		{
			Mage.HP += 3;
			Mage.VIT += 3;
			Mage.HP += 3000;
			Warrior.HP = 10000;
			rounds += 1;
			enemiesKilled += 1;
			cout << "You defeated Warrior!" << endl;
			cout << endl;
			system("pause");
			system("cls");
		}
	}
	else if(answer == "Mage" && mageTurn == "Assassin") //Mage VS Assassin
	{
		for(int i = 0;i < 10000; i++)
		{
		Mage.HP -= assassinAttack;
		Assassin.HP -= mageAttack;

		cout << "Mage's HP: " << Mage.HP << endl;
		cout << "Assassin's HP: " << Assassin.HP << endl;
		cout << endl;
		cout << "Mage's Damage: " << mageAttack << endl;
		cout << "Assassin's Damage: " << assassinAttack << endl;
		cout << endl;
		system("pause");
		system("cls");
		}
		if(Assassin.HP < zero)
		{
			Mage.AGI += 3;
			Mage.DEX += 3;
			Mage.HP += 3000;
			Assassin.HP = 10000;
			rounds += 1;
			enemiesKilled += 1;
			cout << "You defeated Assassin!" << endl;
			cout << endl;
			system("pause");
			system("cls");
		}
	}

	//If player Assassin
	if(answer == "Assassin" && assassinTurn == "Mage") //Assassin VS Mage
	{
		for(int i = 0;i < 10000; i++)
		{
		Assassin.HP -= mageAttack;
		Mage.HP -= assassinAttack;

		cout << "Assassin's HP: " << Assassin.HP << endl;
		cout << "Mage's HP: " << Mage.HP << endl;
		cout << endl;
		cout << "Assassin's Damage: " << assassinAttack << endl;
		cout << "Mage's Damage: " << mageAttack << endl;
		cout << endl;
		system("pause");
		system("cls");
		}
		if(Mage.HP < zero)
		{
			Assassin.POW += 5;
			Assassin.HP += 3000;
			Mage.HP = 10000;
			rounds += 1;
			enemiesKilled += 1;
			cout << "You defeated Mage!" << endl;
			cout << endl;
			system("pause");
			system("cls");
		}
	}
	else if(answer == "Assassin" && assassinTurn == "Warrior") //Assassin VS Warrior
	{
		for(int i = 0;i < 10000; i++)
		{
		Assassin.HP -= warriorAttack;
		Warrior.HP -= assassinAttack;

		cout << "Assasin's HP: " << Assassin.HP << endl;
		cout << "Warrior's HP: " << Warrior.HP << endl;
		cout << endl;
		cout << "Assasin's Damage: " << assassinAttack << endl;
		cout << "Warrior's Damage: " << warriorAttack << endl;
		cout << endl;
		system("pause");
		system("cls");
		}
		if(Warrior.HP < zero)
		{
			Assassin.HP += 3;
			Assassin.VIT += 3;
			Assassin.HP += 3000;
			Warrior.HP = 10000;
			rounds += 1;
			enemiesKilled += 1;
			cout << "You defeated Warrior!" << endl;
			cout << endl;
			system("pause");
			system("cls");
		}
	}

	//If player Class dies
	if(Warrior.HP < zero)
	{
		ifPlayerHPZero();
	}
	if(Mage.HP < zero)
	{
		ifPlayerHPZero();
	}
	if(Assassin.HP < zero)
	{
		ifPlayerHPZero();
	}
	ifPlayerHPZero();
	return 0;
}
Last edited on
How are we supposed to tell why you think the code isn't working?

Also, you use a variable zero that can be changed. How can you sure you're comparing against the value zero.
When I run the program, the HP of the classes Warrior,Mage and Assassin goes to negative , but I coded that if the HP < 0, it will do something.Any help pls?
Last edited on
Those for loops, you need to break out of them if the relevant HP goes negative.
Topic archived. No new replies allowed.