Why won't this compile?

closed account (EAUX92yv)
I use the Visual Studio 2012 Express compiler. I decided to make a large text-based game for practice. I still in the beginning, but when I test it, it won't compile and gives the error that the end of the file is found before the left brace. I don't believe I am missing any brackets. Here is my code with our the variables or includes:

int _tmain(int argc, _TCHAR* argv[])
{
cout<<"Welcome to Zombie Horde Survival! In this world, zombies have infected\n";
cout<<"the entire world, aside from certain few survivors. You are one of them.\n";
Sleep(4000);
system("CLS");
cout<<"Before you set off to survive, let's learn a bit about you.\n";
cout<<"Are you\n";
cout<<"A. Male or\n";
cout<<"B. Female?\n";
cin>>choice1;
if (choice1=='a' || 'A')
{
gender="male";
}
else if (choice1=='b' || 'B')
{
gender="female";
}
else
{
cout<<"That is not a valid choice. Please try again.\n";
cin>>choice1;
}
cout<<"Now that we've got that settled, what is your name? If you have played before\n";
cout<<"and you have obtained a spawn code, you can type it here as well.\n";
cin>>name;
cout<<"So your name is ";
cout<<name;
cout<<"?";
Sleep(2000);
system("CLS");
cout<<"You wake up in your bed. It is a fine looking\n";
cout<<"morning outside. All of a sudden, you hear\n";
cout<<"a groan and look out the window. You see a \n";
cout<<"group of pale looking bloody people walking around\n";
cout<<"outside. You wonder what this is about.\n";
Sleep(7000);
system("CLS");
cout<<"You decide to get some breakfast to eat. You\n";
cout<<"grab an omellette and quickly finish it off.\n";
cout<<"You run outside and quickly ask,";
cout<<"\"Are you okay?\"\n";
cout<<"All you hear is a groan. The people lunge at\n";
cout<<"you and try to claw off your flesh. One of them\n";
cout<<"succeeds and claw off a protion of skin of you\n";
cout<<"right arm. You run back inside your house as\n";
cout<<"fast as you can. What in the world was that?\n";
Sleep(8000);
system("CLS");
cout<<"You have time to grab one item before these monsters\n";
cout<<"get to you. What do you choose?\n";
cout<<"A. a butcher knife\n";
cout<<"B. a pouch of steak knifes\n";
cout<<"C. a burning fire tender\n";
cout<<"D. a walking stick\n";
cin>>choice2;
if (choice2=='a' || 'A')
{
weapon="butcher knife";
weapondamage=10;
}
else if (choice2=='b' || 'B')
{
weapon="pouch of knives";
weapondamage=10;
}
else if (choice2=='c' || 'C')
{
weapon="fire tender";
weapondamage=4;
}
else if (choice2=='d' || 'D')
{
weapon="walking stick";
weapondamage=5;
}
else
{
cout<<"That is not a valid answer. Please try again.\n";
cin>>choice2;
}
cout<<"A fine choice! A ";
cout<<weapon;
cout<<" will help you very efficiently\n";
cout<<"to defend yourself against these \n";
cout<<"monstrous things! You run to your door\n";
cout<<"and find that they are almost through.\n";
cout<<"You grab your ";
cout<<weapon;
cout<<" and attack them.\n";
Sleep(5000);
system("CLS");
cout<<"Welcome to the combat tutorial! While in combat, your team \n";
cout<<"and your opponent(s) will switch off attacking each other. You \n";
cout<<"can attack with your normal weapon, you can dodge, or you can\n";
cout<<"use an item. You can only hold up to 20 items in your inventory,\n";
cout<<"so beware to only pick up items you need. The battler with \n";
cout<<"the highest speed stat gets to go first in combat. Your weapon and\n";
cout<<"your strength stat determines how much damage you do to your\n";
cout<<"opponent(s). Some weapons are better than others. You can increase \n";
cout<<"your stats through mission choices that require those skills, through\n";
cout<<"training at specialized facilities such as gyms, or by learning from\n";
cout<<"an ally. Try fighting these 4 zombies by yourself.\n";
Sleep(7000);
system("CLS");
class battle;
{
char battlechoice;
int battlecode=1;
if (battlecode=1)
{
enemydefense=2;
enemyattack=5;
enemyspeed=5;
enemyhealth=20;
}
while (enemyhealth>0)
{

}//Don't forget to program in the other battle codes for the battle class to work every time!
bool firstattack; //true=player attacks first, false=enemy attacks first
int playerattackdamage=attack+weapondamage-enemydefense;
if (speed>enemyspeed)
{
firstattack=true;
}
else if(speed<enemyspeed)
{
firstattack=false;
}
cout<<"Your health:";
cout<<health;
cout<<".\n";
cout<<"Your enemy's health:";
cout<<enemyhealth;
cout<<".\n";
Sleep(3000);
cout<<"You can currently do the following:\n";
cout<<"A. attack with your weapon\n";
cout<<"B. dodge your enemy's attack\n";
cin>>battlechoice;
if (battlechoice='a' || 'A')
{
cout<<"You attack with your ";
cout<<weapon;
cout<<".\n";
enemyhealth=enemyhealth-playerattackdamage;
Sleep(3000);
}
else if (battlechoice='b' || 'B')
{
bool dodgeattack=true;
cout<<"You dodge the enemy attack.\n";
Sleep(3000);
}
Sleep(2000);
system("CLS");
cout<<"Now that the humans are still and \n";
cout<<"not trying to kill you, you notice\n";
cout<<"that they are not at all humans. They\n";
cout<<"are seemingly zombies. Do you \n";
cout<<"think they are\n";
cout<<"A. zombies or\n";
cout<<"B. cannibals?\n";
cin>>choice3;
if (choice3='a' || 'A')
{
cout<<"They are definitely zombies,\n";
cout<<"just real zombies.\n";
}
else if (choice3='b' || 'B')
{
cout<<"They must be cannibals, there\n";
cout<<"is no other logical solution.\n";
Sleep(3000);
system("CLS");
}
cout<<"Now that you have decided that, you\n";
cout<<"look across the street and see that\n";
cout<<"there are dozens and dozens more of those\n";
cout<<"things, and they all see you. You must\n";
cout<<"run, and fast! You must make one large\n";
cout<<"choice. You can go north, east, south, or\n";
cout<<"west. Where do you want to go?\n";
cout<<"A. North.\n";
cout<<"B. East.\n";
cout<<"C. South.\n";
cout<<"D. West.\n";//Don't forget the else if parts!
cin>>choice4;
if (choice4='a' || 'A')
{
Sleep(4000);
system("CLS");
cout<<"You decide to go north for the time\n";
cout<<"being. Any direction is good, right?\n";
cout<<"As you begin to run further north, the \n";
cout<<"things chase after you. You begin to \n";
cout<<"grow tired. Should you stop and take a \n";
cout<<"break somewhere, or should you keep going?\n";
cout<<"A. take a break.\n";
cout<<"B. keep going.\n";
cin>>choice5;
Sleep(3000);
system("CLS");
if (choice5= 'a' || 'A')
{
cout<<"You decide it's better to save your\n";
cout<<"energy for another time. You see an \n";
cout<<"abandoned fast food restaurant and a \n";
cout<<"dark subway station. Which do you want\n";
cout<<"to take a break in?\n";
cout<<"A. the fast food.\n";
cout<<"B. the subway.\n";
cin>>choice6;
if (choice6='a' || 'A')
{
cout<<"You figure the fast food restaurant\n";
cout<<"will have some food left for you to \n";
cout<<"eat, and you can see that it is safe.\n";
cout<<"You enter the restaurant and see that\n";
cout<<"it has been visited. The walls are \n";
cout<<"stained with blood, and the cabinets \n";
cout<<"in the kitchen are torn apart and ruined\n";
cout<<"from those monsters and most likely other\n";
cout<<"survivors as well. For how long do you \n";
cout<<"want to rest here for?\n";
cout<<"A. 1 hour\n";
cout<<"B. 2 hours\n";
cout<<"C. 3 hours\n";
cout<<"D. 4 hours\n";
cin>>choice7;
Sleep(5000);
system("CLS");
if (choice7='a' || 'A')
{
cout<<"You decide to rest for a short 1 hour,\n";
cout<<"then you get off and hit the road.\n";
}
else if (choice7='b' || 'B')
{
cout<<"You sleep for 2 hours, and when you wake up,\n";
cout<<"you get back to the road.\n";\
}
else if (choice7='c' || 'C')
{
cout<<"You relax there for a good 3 hours, and you \n";
cout<<"then get to the road.\n";
}
else if (choice7='d'|| 'D')
{
cout<<"You rest for a long 4 hours, before you\n";
cout<<" get back to the road.\n";
}
Sleep(4000);
system ("CLS");
cout<<"You enjoy your break, but you know that you must\n";
cout<<"get back on the road. The skies are gloomy and\n";
}
else if (choice6-='b' || 'B')
{
}
}
else if (choice5='b' || 'B')
{
}
}
}

Where did I go wrong with this and how can I fix it? A quick thanks in advance!
Learn to post code.

> I don't believe I am missing any brackets.
You do. indent your code and you'll see it.
closed account (EAUX92yv)
Here is the code:

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
int _tmain(int argc, _TCHAR* argv[])
{
cout<<"Welcome to Zombie Horde Survival!  In this world, zombies have infected\n";
cout<<"the entire world, aside from certain few survivors.  You are one of them.\n";
Sleep(4000);
system("CLS");
cout<<"Before you set off to survive, let's learn a bit about you.\n";
cout<<"Are you\n";
cout<<"A. Male or\n";
cout<<"B. Female?\n";
cin>>choice1;
if (choice1=='a' || 'A')
{
gender="male";
}
else if (choice1=='b' || 'B')
{
gender="female";
}
else 
{
cout<<"That is not a valid choice.  Please try again.\n";
cin>>choice1;
}
cout<<"Now that we've got that settled, what is your name?  If you have played before\n";
cout<<"and you have obtained a spawn code, you can type it here as well.\n";
cin>>name;
cout<<"So your name is ";
cout<<name;
cout<<"?";
Sleep(2000);
system("CLS");
cout<<"You wake up in your bed.  It is a fine looking\n";
cout<<"morning outside.  All of a sudden, you hear\n";
cout<<"a groan and look out the window.  You see a \n";
cout<<"group of pale looking bloody people walking around\n";
cout<<"outside.  You wonder what this is about.\n";
Sleep(7000);
system("CLS");
cout<<"You decide to get some breakfast to eat.  You\n";
cout<<"grab an omellette and quickly finish it off.\n";
cout<<"You run outside and quickly ask,";
cout<<"\"Are you okay?\"\n";
cout<<"All you hear is a groan.  The people lunge at\n";
cout<<"you and try to claw off your flesh.  One of them\n";
cout<<"succeeds and claw off a protion of skin of you\n";
cout<<"right arm.  You run back inside your house as\n";
cout<<"fast as you can.  What in the world was that?\n";
Sleep(8000);
system("CLS");
cout<<"You have time to grab one item before these monsters\n";
cout<<"get to you.  What do you choose?\n";
cout<<"A. a butcher knife\n";
cout<<"B. a pouch of steak knifes\n";
cout<<"C. a burning fire tender\n";
cout<<"D. a walking stick\n";
cin>>choice2;
if (choice2=='a' || 'A')
{
weapon="butcher knife";
weapondamage=10;
}
else if (choice2=='b' || 'B')
{
weapon="pouch of knives";
weapondamage=10;
}
else if (choice2=='c' || 'C')
{
weapon="fire tender";
weapondamage=4;
}
else if (choice2=='d' || 'D')
{
weapon="walking stick";
weapondamage=5;
}
else 
{
cout<<"That is not a valid answer.  Please try again.\n";
cin>>choice2;
}
cout<<"A fine choice!  A ";
cout<<weapon;
cout<<" will help you very efficiently\n";
cout<<"to defend yourself against these \n";
cout<<"monstrous things!  You run to your door\n";
cout<<"and find that they are almost through.\n"; 
cout<<"You grab your ";
cout<<weapon;
cout<<" and attack them.\n";
Sleep(5000);
system("CLS");
cout<<"Welcome to the combat tutorial!  While in combat, your team \n";
cout<<"and your opponent(s) will switch off attacking each other.  You \n";
cout<<"can attack with your normal weapon, you can dodge, or you can\n";
cout<<"use an item.  You can only hold up to 20 items in your inventory,\n";
cout<<"so beware to only pick up items you need.  The battler with \n";
cout<<"the highest speed stat gets to go first in combat.  Your weapon and\n";
cout<<"your strength  stat determines how much damage you do to your\n";
cout<<"opponent(s).  Some weapons are better than others.  You can increase \n";
cout<<"your stats through mission choices that require those skills, through\n";
cout<<"training at specialized facilities such as gyms, or by learning from\n";
cout<<"an ally.  Try fighting these 4 zombies by yourself.\n";
Sleep(7000);
system("CLS");
	class battle;
	{
	char battlechoice;
int battlecode=1;
	if (battlecode=1)
	{
	enemydefense=2;
	enemyattack=5;
	enemyspeed=5;
	enemyhealth=20;
	}
	while (enemyhealth>0)
	{
	
}//Don't forget to program in the other battle codes for the battle class to work every time!
bool firstattack; //true=player attacks first, false=enemy attacks first
int playerattackdamage=attack+weapondamage-enemydefense;
	if (speed>enemyspeed)
	{
		firstattack=true;
	}
	else if(speed<enemyspeed)
	{
		firstattack=false;
	}
	cout<<"Your health:";
	cout<<health;
	cout<<".\n";
	cout<<"Your enemy's health:";
	cout<<enemyhealth;
	cout<<".\n";
	Sleep(3000);
	cout<<"You can currently do the following:\n";
	cout<<"A. attack with your weapon\n";
	cout<<"B. dodge your enemy's attack\n";
	cin>>battlechoice;
	if (battlechoice='a' || 'A')
		{
		cout<<"You attack with your ";
		cout<<weapon;
		cout<<".\n";
		enemyhealth=enemyhealth-playerattackdamage;
		Sleep(3000);
	}
	else if (battlechoice='b' || 'B')
	{
		bool dodgeattack=true;
		cout<<"You dodge the enemy attack.\n";
		Sleep(3000);
	}
	Sleep(2000);
	system("CLS");
	cout<<"Now that the humans are still and \n";
	cout<<"not trying to kill you, you notice\n";
	cout<<"that they are not at all humans.  They\n";
	cout<<"are seemingly zombies.  Do you \n";
	cout<<"think they are\n";
	cout<<"A. zombies or\n";
	cout<<"B. cannibals?\n";
	cin>>choice3;
	if (choice3='a' || 'A')
	{
		cout<<"They are definitely zombies,\n";
		cout<<"just real zombies.\n";
	}
	else if (choice3='b' || 'B')
	{
		cout<<"They must be cannibals, there\n";
		cout<<"is no other logical solution.\n";
		Sleep(3000);
		system("CLS");
	}
	cout<<"Now that you have decided that, you\n";
	cout<<"look across the street and see that\n";
	cout<<"there are dozens and dozens more of those\n";
	cout<<"things, and they all see you.  You must\n";
	cout<<"run, and fast!  You must make one large\n";
	cout<<"choice.  You can go north, east, south, or\n";
	cout<<"west.  Where do you want to go?\n";
	cout<<"A. North.\n";
	cout<<"B. East.\n";
	cout<<"C. South.\n";
	cout<<"D. West.\n";//Don't forget the else if parts!
	cin>>choice4;
	if (choice4='a' || 'A')
	{
		Sleep(4000);
		system("CLS");
		cout<<"You decide to go north for the time\n";
		cout<<"being.  Any direction is good, right?\n";
		cout<<"As you begin to run further north, the \n";
		cout<<"things chase after you.  You begin to \n";
		cout<<"grow tired.  Should you stop and take a \n";
		cout<<"break somewhere, or should you keep going?\n";
		cout<<"A. take a break.\n";
		cout<<"B. keep going.\n";
		cin>>choice5;
		Sleep(3000);
		system("CLS");
		if (choice5= 'a' || 'A')
		{
			cout<<"You decide it's better to save your\n";
			cout<<"energy for another time.  You see an \n";
			cout<<"abandoned fast food restaurant and a \n";
			cout<<"dark subway station.  Which do you want\n";
			cout<<"to take a break in?\n";
			cout<<"A. the fast food.\n";
			cout<<"B. the subway.\n";
			cin>>choice6;
				if (choice6='a' || 'A')
				{
					cout<<"You figure the fast food restaurant\n";
					cout<<"will have some food left for you to \n";
					cout<<"eat, and you can see that it is safe.\n";
					cout<<"You enter the restaurant and see that\n";
					cout<<"it has been visited.  The walls are \n";
					cout<<"stained with blood, and the cabinets \n";
					cout<<"in the kitchen are torn apart and ruined\n";
					cout<<"from those monsters and most likely other\n";
					cout<<"survivors as well.  For how long do you \n";
					cout<<"want to rest here for?\n";
					cout<<"A. 1 hour\n";
					cout<<"B. 2 hours\n";
					cout<<"C. 3 hours\n";
					cout<<"D. 4 hours\n";
					cin>>choice7;
					Sleep(5000);
					system("CLS");
					if (choice7='a' || 'A')
					{
						cout<<"You decide to rest for a short 1 hour,\n";
						cout<<"then you get off and hit the road.\n";
					}
					else if (choice7='b' || 'B')
					{
						cout<<"You sleep for 2 hours, and when you wake up,\n";
						cout<<"you get back to the road.\n";\
					}
					else if (choice7='c' || 'C')
					{
					cout<<"You relax there for a good 3 hours, and you \n";
					cout<<"then get to the road.\n";
					}
					else if (choice7='d'|| 'D')
					{
						cout<<"You rest for a long 4 hours, before you\n";
						cout<<" get back to the road.\n";
					}
					Sleep(4000);
					system ("CLS");
					cout<<"You enjoy your break, but you know that you must\n";
					cout<<"get back on the road.  The skies are gloomy and\n";
				}
				else if (choice6-='b' || 'B')
				{
				}
		}
		else if (choice5='b' || 'B')
		{
		}
	}
	}	
Last edited on
closed account (EAUX92yv)
Where should I add a bracket to fix the problem?
I would first start by encompassing each if statement with a ending bracket.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
if (choice4='a' || 'A')
	{
		Sleep(4000);
		system("CLS");
		cout<<"You decide to go north for the time\n";
		cout<<"being.  Any direction is good, right?\n";
		cout<<"As you begin to run further north, the \n";
		cout<<"things chase after you.  You begin to \n";
		cout<<"grow tired.  Should you stop and take a \n";
		cout<<"break somewhere, or should you keep going?\n";
		cout<<"A. take a break.\n";
		cout<<"B. keep going.\n";
		cin>>choice5;
		Sleep(3000);
		system("CLS");
} // added 


And the correct way to check the if is..
if (choice4=='a' || choice4=='A')
You need double == to check for sameness. A single =, is to assign a value.
closed account (EAUX92yv)
Alright. Thanks for the help. I was able to get it to work. Thanks!
Topic archived. No new replies allowed.