What's wrong with my code?

closed account (LyUoGNh0)
What's wrong with my code? I get 2 errors, 1: illegal else without matching if line 93. and 2: end of file found before the left brace '{' at 'Filename.cpp(29)' was matched line 259. Please help! This is my first real attempt at making a program entirely by myself but I need some advice. I know it has probably something to do with the organization of the blocks and the semi-colons.

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
#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;

int game_Is_Running = 1;

int main ()
{

	// Intro
	cout << "Welcome to The Cave of Two Lovers." << endl;
	cout << "By OR Software." << endl;
	cout << "http://www.ORSoftware.netne.net/" << endl;
	system("pause");
	system("cls");

	int user_Input, right_Way, score;
	string character_Select,character_To_Go_With;

	// Game
	loop:
	cout << "You come across a cave with team avatar...." << endl;
	system("pause");
	cout << "Who do you want to be? (Aang, Sokka, or Katara)" << endl;
	cin >> character_Select;

	// Check what character they want to be
	if (character_Select == "Aang") {
		// Play as aang
		cout << "You have chosen to be Aang." << endl;
		system("pause");
		system("cls");
		cout << "You enter the cave..." << endl;
		system("pause");
		cout << "You walk in with Sokka, and Katara." << endl;
		system("pause");
		system("cls");
		cout << "The wall is starting to collapse. You have a choice to go with Katara or Sokka." << endl;
		system("pause");
		cout << "Who do you go with? HURRY YOU HAVE TO PICK SOON!" << endl;
		cin >> character_To_Go_With;
		if (character_To_Go_With == "Katara") {
			// Go with Katara
			int love; // How much love you and Katara have.
			system("cls");
			cout << "You and Katara are now alone...." << endl;
			system("pause");
			cout << "You can't stop thinking about your love for her," << endl;
			cout << "So that will delay you're thinking and reaction time." << endl;
			system("pause");
			system("cls");
			cout << "It's really dark. Katara asked you to hold her hand." << endl;
			cout << "But you also have torches." << endl;
			system("pause");
			cout << "What do you want to do?" << endl;
			int hold_Katara_Hand;
			cout << "(1 = Hold her hand ; 2 = Light a torch)" << endl;
			cin >> hold_Katara_Hand;
			system("cls");

			if (hold_Katara_Hand == 1) {
				// Continue through the cave holding her hand. (LOVE INCREASES BY 1)
				love = love + 1;
				cout << "You and Katara now have a love of " << love << endl;
				system("pause");
				system("cls");

				// The Which way to go loop
				while (game_Is_Running == 1) {
					// generate the right way
					right_Way = 2;

					cout << "You come across a two-way intersection. You can go left (1) or right (2)" << endl;
					cout << "Which way do you want to go?" << endl;	
					cin >> user_Input;
						
					if (user_Input == right_Way) {
						cout << "Congrates! You picked the right way!" << endl;
						score = score + 1;
						cout << "Your score is now " << score << endl;
						system("pause");
						system("cls");
					}else {
						cout << "You picked the wrong way..." << endl;
						score = score - 1;
						cout << "Your score is now " << score << endl;
						system("pause");
						system("cls");

					}			
			}
			else if (hold_Katara_Hand == 2) {
					// Continue through the cave NOT holding her hand, but using a torch. (LOVE DECREASES BY 1)
					love = love - 1;
					cout << "You and Katara now have a love of " << love << endl;
					system("pause");
					system("cls");
					
					// The Which way to go loop
					while (game_Is_Running == 1) {
						// generate the right way
						right_Way = 1;

						cout << "You come across a two-way intersection. You can go left (1) or right (2)" << endl;
						cout << "Which way do you want to go?" << endl;	
						cin >> user_Input;
						
						if (user_Input == right_Way) {
							cout << "Congrates! You picked the right way!" << endl;
							score = score + 1;
							cout << "Your score is now " << score << endl;
							system("pause");
							system("cls");
						}else {
							cout << "You picked the wrong way..." << endl;
							score = score - 1;
							cout << "Your score is now " << score << endl;
							system("pause");
							system("cls");
						}

					}
			}
		}
		else if (character_To_Go_With == "Sokka") {
				// Go with Sokka
				cout << "You chose to go with Sokka" << endl;
				system("pause");
				system("cls");
				cout << "Sokka" << endl;
				system("pause");
				system("cls");
				cout << "Yea Aang?" << endl;
				system("pause");
				system("cls");
				cout << "I need some girl advice..Can you help me out?" << endl;
				system("pause");
				system("cls");
				cout << "Sure. I'm the right guy for that I believe.*rubs chin*" << endl;
				system("pause");
				system("cls");
				cout << "Who do you like Aang?" << endl;
				system("pause");
				system("cls");
				cout << "Well, It's kind of your sister" << endl;
				system("pause");
				system("cls");
				cout << "!_! WAAAT!" << endl;
				system("pause");
				system("cls");
				cout << "Are you mad Sokka?" << endl;
				cout << "No Aang. Le--t's just get out of here." << endl;
				system("pause");
				system("cls");

				// The Which way to go loop
				while (game_Is_Running == 1) {
					// generate the right way
					right_Way = 2;

					cout << "You come across a two-way intersection. You can go left (1) or right (2)" << endl;
					cout << "Which way do you want to go?" << endl;	
					cin >> user_Input;
						
					if (user_Input == right_Way) {
						cout << "Congrates! You picked the right way!" << endl;
						score = score + 1;							
						cout << "Your score is now " << score << endl;
						system("pause");
						system("cls");
					}else {
						cout << "You picked the wrong way..." << endl;
						score = score - 1;
						cout << "Your score is now " << score << endl;
						system("pause");
						system("cls");
						}

				}
             
		}
	}
	else if (character_Select == "Sokka") {
		// Play as sokka
		cout << "You have chosen to be Sokka." << endl;
		system("pause");
		system("cls");
		cout << "You enter the cave..." << endl;
		system("pause");
		cout << "You walk in with Aang and Katara." << endl;
		system("pause");
		system("cls");
		cout << "The wall is starting to collapse. You have a choice to go with Aang or Katara." << endl;
		system("pause");
		cout << "Who do you go with? HURRY YOU HAVE TO PICK SOON!" << endl;
		cin >> character_To_Go_With;

		if (character_To_Go_With == "Aang") {
			// Go with Aang
			cout << "You chose to go with Aang." << endl;

		}
		else if (character_To_Go_With == "Katara") {
			// Go with Katara
			cout << "You chose to go with Katara." << endl;

		}

		while (game_Is_Running == 1) {
			// Loop game
			cout << "This is where the game is going to be" << endl;
			system("pause");
			system("cls");

		}
	}
	else if (character_Select == "Katara") {
		// Play as katara
		cout << "You have chosen to be Katara." << endl;
		system("pause");
		system("cls");

		cout << "You enter the cave..." << endl;
		system("pause");
		cout << "You walk in with Aang, and Sokka." << endl;
		system("pause");
		system("cls");
		cout << "The wall is starting to collapse. You have a choice to go with Aang or Sokka." << endl;
		system("pause");
		cout << "Who do you go with? HURRY YOU HAVE TO PICK SOON!" << endl;
		cin >> character_To_Go_With;

		if (character_To_Go_With == "Aang") {
			cout << "You chose to go with Aang." << endl;
			system("pause");

		}
		else if (character_To_Go_With == "Sokka") {
			cout << "You chose to go with Sokka." << endl;
			system("pause");

		}
		while (game_Is_Running == 1) {
			// Loop game
			cout << "This is where the game is going to be" << endl;
			system("pause");
			system("cls");
		}

	}else {
		cout << "Invalid" << endl;
		system("pause");
		system("cls");
		goto loop;
	}

}
closed account (LyUoGNh0)
NOTE: I use Visual C++.
What's wrong with my code? I get 2 errors, 1: illegal else without matching if line 93. and 2: end of file found before the left brace '{' at 'Filename.cpp(29)' was matched line 259.


Your compiler tells you exactly what's wrong with it. You have an illegal else without a matching if, and your braces don't match up. If you're using Visual C++, put your cursor on the brace on line 93. The matching brace will be highlighted. I bet it isn't the brace on line 62.
closed account (LyUoGNh0)
Thanks! I was actually looking around to see if the braces matched up but didn't see that I missed a '}' for line 70.
Use some functions too :) Here is code of a LifeRPG I am currently developing. I am new to programming too.. so mine is probably really bad ^^

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
345
346
347
348
349
350
351
352
353
354
355
356
357
#include <iostream>
#include <cstdlib>

using namespace std;

//MENU FUNCTION
int LifeMenu(int x ){
x = 3;

string answer;
cout << "WELCOME TO RPG LIFE!!\n\n";
cout << "Press y or n to make choice.\n";
cout << "At anytime, press i to show stats.\n\n";
cout << "Are you ready to play?\n";

cout << "y/n?";
cout << endl;

do{

cout << "Input: ";
cin >> answer;

if(answer == "y"){
    cout << endl;
    cout << "Great!\n";
    x = 1;
    return x;
}
else if(answer == "n"){
    cout << endl;
    cout<< "ok, bye then!!\n";
    x = 0;
    return x;
    }
else cout << "Wrong Input!!!\n\n";
}while(x == 3);

}

int FindMoney(int x, int hp){
string answer;
x = x;
hp = hp;
int y = 3; //Value to manage do-while loop
do{
cout << "You are walking along when you find some money on the ground.\n\n";
cout << "Pick it up?\n";


//Input option

cout << "y/n?\n";
cout << "Input: ";
cin >> answer;
cout << endl;

//if answer is y then pick up the money
if(answer == "y"){
    cout << "You pick up 20 dollars!\n";
    x += 20; // x = x + 20
    return x;
    y = 1;
}

//if answer is n, do not pick up the money
else if(answer == "n"){
    cout << "You leave the money on the ground!\n";
    cout << endl;
    x = x;
    return x;
    y = 2;
}

else if(answer == "i"){
system("CLS");
cout << "Your Inventory:\n\n";
cout << "Money: " << x;
cout << endl;
cout << "Health: " << hp;
cout << endl;
cout << endl;
cout << endl;
cin.get();

}
else cout << "wrong input!\n";

}while( y == 3);

}
int EnterShop(int x, int knife, int hp){
knife = 0;
int y = 3;
string answer;
do{
cout << "You enter a shop and see a pocket knife for 25 dollars.\n";
cout << "Would you like to buy it?\n";



cout << "y/n?\n";
cout << "Input: ";
cin >> answer;
if(answer == "y"){
    if(x >= 25 ){
        cout << "You buy the knife!\n";
        knife = 1;
        y = 1;
        return knife;
        x -= 25;
        return x;
    }
    else cout <<  "You do not have enough money!!\n";
    knife = 0;
}

else if(answer == "n"){
    cout << "You leave the knife on the shelf and walk away\n";
    y = 1;
    return knife;
}
else if(answer == "i"){
system("CLS");
cout << "Your Inventory:\n\n";
cout << "Money: " << x;
cout << endl;
cout << "Health: " << hp;
cout << endl;
cout << endl;
cout << endl;
cin.get();

}
else cout << "Invalid Input!\n";


}while(y != 1);
}
int HostileMan(int x, int knife, int hp){

string answer;
int y = 3;
x = x;
do{
cout << "Upon leaving the shop you are pulled into a back alley\n";
cout << "A dark hooded figure with a low pitched voice says:\n\n";
cout << " 'Give me your MONEY'\n\n";
cout << "Do you want to attack him?\n";


cout << "y/n\n";
cout << "Input: ";
cin >> answer;

if(answer == "y"){
        y = 1;
        system("CLS");
    if(knife == 1 ){
        cout << "You stab the man in the chest and run!\n";
        hp = hp;
        return hp;
        }
    else if(knife == 0){
        cout << "You hit the man, but he breaks your arm\n";
        cout << "He takes your money and runs!\n";
        hp -=60;
        return hp;
}

}


else if(answer == "n"){

    y = 1;
    system("CLS");
    cout << "You make a dart behind you but the man grabs your jumper\n";
    cout << "He then proceeds to rape you....\n";
hp -= 20;
return hp;
}
if(answer == "i"){
system("CLS");
cout << "Your Inventory:\n\n";
cout << "Money: " << x;
cout << endl;
cout << "Health: " << hp;
cout << endl;
if (knife == 1 ){
    cout << "A knife.";
}
cout << endl;
cout << endl;
cout << endl;
cin.get();

}
}while(y != 1);




}
int HaveAShower(int x, int knife,int hp){
string answer;
int y = 3;
system("CLS");

do{
cout << "You quickly make your way back home.\n";
cout << "Would you like to have a shower?\n";
cout << "y/n?\n";
cout << "Input: ";
cin >> answer;

if(answer == "y"){
    y = 1;
    system("CLS");
    cout << "Your hp increases by 25 (if not already at 100)\n";
    if(hp < 100)
        hp += 25;
        if(hp > 100)
            hp = 100;
        return hp;
       }
        else if(answer == "n"){
                y = 1;
    system("CLS");
    cout << "You decide not to have a shower.\n";

}

else if(answer == "i"){
system("CLS");
cout << "Your Inventory:\n\n";
cout << "Money: " << x;
cout << endl;
cout << "Health: " << hp;
cout << endl;
if (knife == 1 ){
    cout << "A knife.";
}
cout << endl;
cout << endl;
cout << endl;
cin.get();

}


}while(y == 3);
}
int SeeMan(int x, int knife, int hp, int enemy){
string answer;
int y = 3;
system("CLS");
enemy = 0;

do{
cout << "You hear a sound at the front door.\n";
cout << "Do you investigate?\n";
cout << "y/n?\n";
cout << "Input: ";
cin >> answer;

if(answer == "y"){
    y = 1;
    system("CLS");
    cout << "You walk to the door and put your eye to the door....\n";
    cout << "To your HORROR you recognise the man in the hoody!!\n";
    enemy = 1;
    return enemy;

}

else if(answer == "n"){
                y = 1;
    system("CLS");
    cout << "You put your focus back onto the TV.\n";
}

else if(answer == "i"){
system("CLS");
cout << "Your Inventory:\n\n";
cout << "Money: " << x;
cout << endl;
cout << "Health: " << hp;
cout << endl;
if (knife == 1 ){
    cout << "A knife.";
}
cout << endl;
cout << endl;
cout << endl;
cin.get();

}


}while(y == 3);

}
int main()
{
//VARIABLES
int play;//play or not play
int money = 5;//Variable to hold amount of money
int weapon = 0;//weapon or no weapon
int health = 100;//health variable
int seen = 0;

play = LifeMenu(play); //play variable is equal to value returned from function

switch(play){ //switch the play variable
  case 1:
      system("CLS"); //clear screen

money = FindMoney(money,health); //money equal to variable of money returned from function

system("CLS");

weapon = EnterShop(money,weapon,health); //weapon variable equal to variable of money returned from function
if(weapon == 1 ) //if brought a weapin, deduct $20 from money variable
{
    money -= 20;
}
system("CLS");

health = HostileMan(money,weapon, health); //Health variable changes depending on fight
if(health != 100 ) //if health not equal to 100...
{
   money -= money; //Take away ALL money
}

health = HaveAShower(money, weapon, health);

seen = SeeMan(money, weapon, health, seen);






  case 2:

break;

  default:

      break;


}


}
closed account (LyUoGNh0)
yea I'm just learning functions now in the PDF i'm learning from. Thanks for the advice. And contact me when the game is finished I'll try it email: overratedprogrammer@gmail.com
Topic archived. No new replies allowed.