Function not calling

Having issues getting the fight_combat function to come up in my program.
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

main.cpp

#include <iostream>
#include <time.h>
#include "fight.h"
#include "player.h"

using namespace std;


int direction;
player  currplayer;
combat B;
	int weapon;

int main ()
{
	

	cout << "Welcome to Z.E.T.A" << endl;
	cout << "“Zombie Elimination Training Academy”" << endl;
	cout << "You have been selected to attempt to enter this elite group." << endl;
	cout << "Your first task is to reach our training facility located at the old airport. " << endl;
	cout << "You can take one weapon from those provided in the room. Good luck." << endl;
	cout << "You see set out on a table. There is a shotgun with 12 shells, a 9mm pistol with 30 rounds, a chainsaw," << endl;
	cout << "a M16 with 60 rounds and a hatchet. " << endl;
	cout << "Choose your weapon. To choose your weapon enter 1 for the Shotgun, 9 for the 9mm, 2 for the chainsaw, " << endl;
	cout << "16 for the M16 and 3 for the Hatchet. " << endl;
	cout << endl;
	cin >> weapon;

			 switch (weapon)
			{
			case  1:
				B.prime = 4;
				B.ammo = 12;
				B.second = 1;
				B.hitchance = 0;
				break;

			case 9:
				B.prime = 1;
				B.ammo = 30;
				B.second = 1;
				B.hitchance = 2;
				break;

			case 2:
				B.prime = 3;
				B.ammo = 1000;
				B.second = 1;
				B.hitchance = 4;
				break;

			case 16:
				B.prime = 2;
				B.ammo = 60;
				B.second = 1;
				B.hitchance = 3;
				break;

			case 3:
				B.prime = 2;
				B.ammo = 1000;
				B.second = 2;
				B.hitchance = 4;
				break;
			
			}  
	


	
			cout << "Now that you have chosen your weapon it is now time to get to the airport."	<< endl;
			cout << "Looking out the window you see a few zombies walking the streets. " <<endl;
			cout << "This is not going to be as easy as it sounds." << endl;
			cout << "You head out down the stairs to get to the facility." << endl; 
			cout << "As you near the bottom floor you hear a faint shuffling sound." << endl;
			cout << " Sounds like it’s time to kill your first zombie." << endl;
		  &combat::fight_combat;
	
		if (B.playerhealth <= 0)
			{
				cout << "You have died!! Guess you were not good enough for Z.E.T.A." << endl;
				cout << "Game over";
				 cin.get();
				cin.get();
				return 0;
			}
		if (B.zombiehealth == 0)
			cout << "That was close hopefully there will not be too many of those." << endl;
	
			cout << "After taking out that zombie you take a moment to collect yourself." << endl; 
			cout << "Walking out the door you see the main road to the airport " << endl;
			cout << "and the back streets and alleys.  The main road has zombies all over it and who knows what you may find taking the alleys. " << endl;
			cout << "Enter 1 to take the road or 2 to go the back way." << endl;
			cin >> direction;

	
	
		if (direction == 1)
		{
			cout << "You start making you way down the road listening carefully for signs of zombies. " << endl;
			cout << "After passing a few abandoned cars you see a zombie shuffling out from behind a car up ahead." << endl;
			&combat::fight_combat;
		if (B.zombiehealth == 0)
			cout << "Well hopefully all that noise doesn’t attract too much attention." <<endl;
			cout << "Heading down the road a bit faster now more and more zombies are coming out behind you." << endl;
			cout << "As you near the entrance of the airport you see 3 zombies chewing on a corpse in the road." << endl; 
			cout << "Looks like you have one more big fight ahead of you." << endl;
			&combat::fight_combat;
		if (B.zombiehealth == 0)
			&combat::fight_combat;
		if (B.zombiehealth == 0)
			&combat::fight_combat;
		if (B.zombiehealth == 0)
			cout << "Well you somehow managed to beat those zombies. Dragging yourself through the gate you feel somehow relived." << endl;
			cout << "A man in a military uniform walks up to you. " << endl;
			cout << "Well done looks like you have what it takes to help us rid the world of this zombie menace." << endl;
			cout << "Welcome to Z.E.T.A." << endl;
			cin.get();
			cin.get();
		return 0;
		}	

		if (direction == 2)
		{
			cout << "Twisting through the side streets you can hear the zombies everywhere but so far have yet to see any." << endl;
			cout << "Suddenly one stumbles out form a dark corner." << endl;
			&combat::fight_combat;
		if (B.zombiehealth == 0)

			cout << "Thankfully you know your way around town. " << endl;
			cout << endl;
			cout << "Taking a few more turns you see a zombie crawling out of a house." << endl;

			&combat::fight_combat;

		if (B.zombiehealth == 0)
			cout << "Just when you think you might have been better off taking the main road you spot the airport employee parking garage. " << endl;
			cout << "Thinking to yourself, wasn’t there a tunnel leading in to the airport in there." <<endl;
			cout << "Making your way through the garage you manage to find the tunnel with little difficulty. " << endl;
			cout << "As you approach the tunnel entrance you see a zombie, who looks like a pilot scratching at the door. " << endl;

			&combat::fight_combat;

		if (B.zombiehealth == 0)
			cout << "After dispatching the zombie pilot you try to open the door only to find it takes a special key. " << endl;
			cout << "Searching around you notice a key card on the pilots belt. Using it to open the door you run through the tunnel to the airport." << endl;
			cout << "When you come out you almost run in to a man in a military uniform. He looks at you and smiles. " << endl;
			cout << "Well done you will do well here. We have needed someone like you for some time now. " << endl;
			cout << "Let’s get you cleaned up and start you training. " << endl;
		if (B.playerhealth == 0 )
			cout << "The zombie pulls you to the ground and starts to devour your flesh. Hopefully you will not feel this too long. Game Over." << endl;
			cin.get();
			cin.get();
			return 0;
		}
			return 0;

}	

fight.cpp

#include <iostream>
#include "fight.h"
#include <time.h>
#include "player.h"
#include "stdlib.h"

using namespace std;

combat A;

combat::combat(void)
{
}
combat::~combat()
{
}


int fight_combat()
{
	A.playerhealth = 10;
	A.zombiehealth = 3;
	int hitmod = 10;
	srand(time(NULL));
	int randhitmod = rand() % 10 +1;


	cout << "Choose your attack. ";
	cout << "Enter 1 to shoot or 2 of Hand to Hand";
	cin >> A.attack;
		if (A.attack == 1)
		{
			if (randhitmod + hitmod >= A.hit)
			cout << "You hit the zombie";
			A.zombiehealth = A.zombiehealth - A.prime, A.ammo --;
				while (A.ammo == 0)
					cout << "Click, click you are out of ammo.";
						A.hitchance = -9999;
			if (randhitmod + hitmod < A.hit)
			cout << "You missed the zombie";
		}
		
		if ( A.attack == 2)
		{
			if (randhitmod + hitmod >= A.hit)
			cout << "You hit the zombie";
			A.zombiehealth = A.zombiehealth - A.second;

			if (randhitmod + hitmod < A.hit)
			cout << "You missed the zombie";

			

			if (A.zombiehitmod + randhitmod >= A.hit)
			cout << "The zombie hits you";
			A.playerhealth = A.playerhealth - 1;

			if (A.zombiehitmod + randhitmod <= A.hit)
			cout << "The zombie missed you";
		}
			while (A.playerhealth >= 0);

			while (A.zombiehealth >= 0);


	return 0;
}

fight.h

#include <iostream>
#ifndef fight_h
#define fight_h
using namespace std;


class combat
{
public:
	combat(void);
	~combat(void);
	int playerhealth; 
	int prime; 
	int second; 
	int ammo; 
	int hit;
	int zombiehealth;
	int randhitmod;
	int hitmod;
	int zombiehitmod ;
	int zombiechop ;
	int hitchance;
	int zombiehitchance ;
	int attack;
	int fight_combat();
};
#endif
player.h
#include <iostream>
#ifndef player_h
#define player_h

using namespace std;

class player
{
public:
	player(void);
	~player(void);
	int weapon;

};
#endif

Player.cpp

#include <iostream>
#include "player.h"
#include "fight.h"
using namespace std;

player::player(void)
{
}
player::~player()
{
}
just call it like this:

 
fight_combat();


You'll need to return something instead of 0, that'll end your program. Return your health, you can't have 10 health every time. You need to return it because of your if statements in main.cpp
That doesn't fix the issue, just creates more it runs the main fine and sees the fight.cpp but doesn't run it.
Your main.cpp has a combat class named B. Just call the B's fight_combat method like what greenleaf said. B.fight_combat()

What were you trying to do when you're calling this guy? &combat::fight_combat;
That ended up giving me a LNK 2019 error.
In fight.cpp

1
2
3
4
5
6
7
8
9
10
11
combat A; // why is this here?

combat::combat(void)
{
}
combat::~combat()
{
}


int fight_combat() // should have combat:: prefix 
Thank you it somewhat works. now just got to look in to some other things now.
I see what you were trying to do. The method fight_combat() is part of the combat class that you made. It's aware of its variables and stuff (So you can call ammo). You're also resetting the playerhealth back to 10 every this function is called.
Yeah i didn't want to reset it each time. I still need to set the zombie variables and now it stops right after the first time an attack is chosen. and doesn't go back.
Topic archived. No new replies allowed.