LNK 2005 error

Everything was going good then I got this error. please help?
main 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
#include <iostream>
#include <time.h>
#include "fight.h"

using namespace std;


char direction;


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

	switch (weapon)
		{

	case  (1):
			prime = 4;
			ammo = 12;
			second = 1;
			hitchance = 0;
			break;

	case (9):
			prime = 1;
			ammo = 30;
			second = 1;
			hitchance = 2;
			break;

	case (2):
			prime = 3;
			ammo = 1000;
			second = 1;
			hitchance = 4;
			break;

	case (16):
			prime = 2;
			ammo = 60;
			second = 1;
			hitchance = 3;
			break;

	case (3):
			prime = 2;
			ammo = 1000;
			second = 2;
			hitchance = 4;
			break;

	}
	cout << "Now that you have chosen your weapon it’s now time to get to the airport. Looking out the window you see a few zombies walking the streets. ";
	cout << "This is not going to be as easy as it sounds.";
	cout << "You head out down the stairs to get to the facility. As you near the bottom floor you hear a faint shuffling sound.";
	cout << " Sounds like it’s time to kill your first zombie.";
	cout << endl;
	  int combat();
	
	if (playerhealth = 0)
		cout << "You have died!! Guess you weren’t good enough for Z.E.T.A.";
		cout << "Game over";
	if (zombiehealth = 0)
		cout << "That was close hopefully there won’t be too many of those.";
	
cout << "After taking out that zombie you take a moment to collect yourself. Walking out the door you see the main road to the airport ";
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. ";
cout << "Enter 1 to take the road or 2 to go the back way.";
cin >> direction;

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

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

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

int combat();

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

int combat();

	if (zombiehealth = 0)
	cout << "After dispatching the zombie pilot you try to open the door only to find it takes a special key. ";
	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.";
	cout << endl;
cout << "When you come out you almost run in to a man in a military uniform. He looks at you and smiles. ";
cout << "Well done you will do well here. We have needed someone like you for some time now. Let’s get you cleaned up and start you training. ";
if (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.";
	

	return 0;

}	


The header file.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>

using namespace std;

int playerhealth;
int zombiehealth;
int weapon;
int prime;
int second;
int ammo;
int hit;
int randhitmod;
int hitmod;
int zombiehitmod;
int zombiechop;
int secammo;
int hitchance;
int zombiehitchance;
char attack;


And the combat 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
#include <iostream>
#include "fight.h"
#include "time.h"

using namespace std;

int fight (int combat)
{
	playerhealth = 10;
	zombiehealth = 3;
	hit = 10;
	srand(time(NULL));
	randhitmod = rand() % 10 +1;
	cout << "Choose your attack. ";
	cout << "Enter 1 to shoot or 2 of Hand to Hand";
	cin >> attack;
		if (attack = 1)
		if (randhitmod + hitmod >= hit)
			cout << "You hit the zombie";
			zombiehealth = zombiehealth - prime, ammo --;
				while (ammo = 0)
					cout << "Click, click you are out of ammo.";
						hitchance = -9999;
		if (randhitmod + hitmod < hit)
			cout << "You missed the zombie";
		if ( attack = 2)
			if (randhitmod + hitmod >= hit)
			cout << "You hit the zombie";
			zombiehealth = zombiehealth - second;
			if (randhitmod + hitmod < hit)
			cout << "You missed the zombie";

		if (randhitmod + hitmod < hit)
			cout << "You missed the zombie";
	if (zombiehitmod + randhitmod >= hit)
	 cout << "The zombie hits you";
	 playerhealth = playerhealth - 1;
	if (zombiehitmod + randhitmod < hit)
		cout << "The zombie missed you";
	while (playerhealth >= 0);
	while (zombiehealth >= 0);

	return 0;
}

This is supposed to be just a simple text based game with nothing special about it just need to get it to work.
Line 85 is a function declaration - and there is no such function definition for the function combat.

In future post the full text of the linker error - it should give the name of the function in question.

Edit: You have some other problems:

There are lots of these:
if (zombiehealth = 0) //use equality operator not assignment

This:
while (playerhealth >= 0);

does nothing. Usually for newbies this means it should have been an if statement, but you don't have anything of meaning after it.

You also need to make more use of functions, rather than continuing the story line with more & more lines of code. Especially for menu options.

Hope this helps :)
Last edited on
This is the error i keep getting.
1>Build started 12/10/2012 12:45:47 AM.
1>InitializeBuildStatus:
1> Touching "Debug\ZETA.unsuccessfulbuild".
1>ClCompile:
1> All outputs are up-to-date.
1>Intro.obj : error LNK2005: "int randhitmod" (?randhitmod@@3HA) already defined in fight.obj
1>Intro.obj : error LNK2005: "int second" (?second@@3HA) already defined in fight.obj
1>Intro.obj : error LNK2005: "int zombiechop" (?zombiechop@@3HA) already defined in fight.obj
1>Intro.obj : error LNK2005: "int hitchance" (?hitchance@@3HA) already defined in fight.obj
1>Intro.obj : error LNK2005: "int weapon" (?weapon@@3HA) already defined in fight.obj
1>Intro.obj : error LNK2005: "int hit" (?hit@@3HA) already defined in fight.obj
1>Intro.obj : error LNK2005: "int ammo" (?ammo@@3HA) already defined in fight.obj
1>Intro.obj : error LNK2005: "int zombiehealth" (?zombiehealth@@3HA) already defined in fight.obj
1>Intro.obj : error LNK2005: "int secammo" (?secammo@@3HA) already defined in fight.obj
1>Intro.obj : error LNK2005: "int prime" (?prime@@3HA) already defined in fight.obj
1>Intro.obj : error LNK2005: "int zombiehitmod" (?zombiehitmod@@3HA) already defined in fight.obj
1>Intro.obj : error LNK2005: "int zombiehitchance" (?zombiehitchance@@3HA) already defined in fight.obj
1>Intro.obj : error LNK2005: "int playerhealth" (?playerhealth@@3HA) already defined in fight.obj
1>Intro.obj : error LNK2005: "char attack" (?attack@@3DA) already defined in fight.obj
1>Intro.obj : error LNK2005: "int hitmod" (?hitmod@@3HA) already defined in fight.obj
1>C:\Users\Eric\Documents\Visual Studio 2010\Projects\ZETA\Debug\ZETA.exe : fatal error LNK1169: one or more multiply defined symbols found
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:00.47
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
OK, so you need header guards:

http://en.wikipedia.org/wiki/Include_guard


The other problems I mentioned are still problems. Line 85 in main() should have been a compile error.
> Line 85 in main() should have been a compile error.
No. As you say, it's a function declaration, ¿why should be a compile error?
Topic archived. No new replies allowed.