| cstarter2000 (90) | |
|
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! | |
|
|
|
| ne555 (4385) | |
|
Learn to post code. > I don't believe I am missing any brackets. You do. indent your code and you'll see it. | |
|
|
|
| cstarter2000 (90) | |||
Here is the code:
| |||
|
Last edited on
|
|||
| cstarter2000 (90) | |
| Where should I add a bracket to fix the problem? | |
|
|
|
| whitenite1 (751) | |||
I would first start by encompassing each if statement with a ending bracket.
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. | |||
|
|
|||
| cstarter2000 (90) | |
| Alright. Thanks for the help. I was able to get it to work. Thanks! | |
|
|
|