Thread: Can't find error

  1. #1
    Registered User
    Join Date
    May 2007
    Posts
    21

    Exclamation Can't find error

    I am making my first text based game. When I show the code please don't gasp at how horribly I organize my code. I know it is bad, but that isn't the issue. I checked my last function but every time I try to build and compile it, it gives me this error-
    "1>c:\documents and settings\owner\my documents\visual studio 2005\projects\textbasedgame\textbasedgame\textgame .cpp(167) : error C2059: syntax error : '}'"

    This shows an error on the last line of the code
    here is the code:

    Code:
    #include<iostream>
    #include<time.h>
    #include<cstring>
    #include<string>
    using namespace std;
    	
    	int lvl;
    	int experience;
    
    	int base;
    	int action;
    	int damage;
    	int magicdamage;
    	string type;
    	int money = 500;
    	string gender;
    	int health = 100;
    	int excess;
    	string name;
    	void goblinbattle();
    	int battleaction;
    	string battleaction2;
    	int wis = 5;
    	int str = 5;
    	int agi = 5;
    
    int main()
    {
    	int gender1;
    
    
    
    	cout<<"Welcome to the world of Leflorin.\n";
    	cout<<"Here you will fight evil monsters and become powerful.\n";
    	cout<<"You fight for your nation, you fight to bring down the evil Scylla!\n";
    	cout<<"Are you ready... \n";
    	system("PAUSE");
    	while(base > 3 || base < 1)
    	{
    	system("cls");
    	cout<<"Choose your base stat: \n";
    	cout<<"1. Wizard: Powerful in all magics\n";
    	cout<<"2. Warrior: Powerful with all weapons\n";
    	cout<<"3. Thief: Quick and nimble\n";
    	cout<<"Choose now... ";
    	cin>>base;
    	if(base > 3 || base < 1 || !base)
    	{
    		cout<<"Incorrect entry";
    		cin.clear();
    		cin.ignore(80, '\n');
    	}
    	}
    	switch(base)
    	{
    	case 1:
    		{
    		wis++;
    		type = "wizard";
    		}
    		break;
    	case 2:
    		{
    		str++;
    		type = "warrior";
    		}
    		break;
    	case 3:
    		{
    		agi++;
    		type = "Thief";
    		}
    		break;
    	default:
    		{
    		cout<<"Incorrect entry";
    		}
    		break;
    	}
    	system("cls");
    		cout<<"Congratulations, after much hard work, you have become a "<<type<<"!\n";
    		cout<<"Your stats are now: \n";
    		cout<<"wisdom: "<<wis<<"\nStrength: "<<str<<"\nAgility: "<<agi<<"\n";
    		system("PAUSE");
    		system("cls");
    		cin.clear();
    		cin.ignore(80, '\n');
    		cout<<"Now choose your gender:\n1. Male\n2. Female\n";
    		cin>>gender1;
    		if(!gender1)
    		{
    			cout<<"Incorrect entry.";
    			cin.clear();
    			cin.ignore(80, '\n');
    		}
    		switch(gender1)
    		{
    		case 1:
    			{
    				gender = "Male";
    			}
    			break;
    		case 2:
    			{
    				gender = "Female";
    			}
    			break;
    		default:
    			{
    				cout<<"Incorrect entry.";
    			}
    		}
    		
    		cout<<"Now that we know your a "<<gender<<", we need to know\nwhat your name is.\n";
    		cin>>name;
    		cout<<"\n";
    		cout<<"What a powerful name, "<<name<<" is!\n";
    		system("cls");
    		cout<<"Lets review your information:\nType:\n     "<<type<<"\nGender:\n     "<<gender<<"\nName:\n     "<<name<<"\n";
    		cout<<"Now you are ready to begin your struggle!";
    		system("PAUSE");
    		system("cls");
    		cout<<"You lie on a cot in your barn after many hours of hard work. When you wake up you hear\na crackle as if something is burning...";
    		cout<<"\nYou hasten to the door where you see a goblin with a torch.\nYour whole house is a giant, smoldering, decayed pile of ash.\n";
    		cout<<"The goblin turns to look at you, his eyes a dull grey.\nYou slowly draw your sword, deep inside yourself\nyou draw on your abilities.";
    		cout<<"Anger, hate, revenge swells up inside of you!\nIt is time to fight\n";
    		system("PAUSE");
    		goblinbattle();
    		system("PAUSE");
    		return 0;
    }
    void goblinbattle()
    {
    	do
    	{
    	srand ( time(NULL) );
    	
    	damage = rand() % str + 1;
    	magicdamage = rand() % wis + 1;
    	int gobstr = 4; 
    	int gobhealth;
    	gobhealth = 25;
    	cout<<"Choose your action: \n";
    	cout<<"1. Melee\n2. Magic\n3. Rest\n";
    	cin>>battleaction;
    	
    	switch(battleaction)
    	{
    	case 1:
    		{
    			action = rand() % 100 + 1;
    			if(action <= (35 - str))
    			{
    			cout<<"You miss the enemy with your sword.\n";
    			cout<<"The enemy has "<<gobhealth<<" health left.\n";
    			}
    			else
    			{
    				cout<<"You cut deep into the enemy.\n";
    				cout<<"You do " <<damage<<" damage to the enemy.\n";
    				cout<<"He has " <<(gobhealth - damage)<<" health left.\n";
    			}
    		}
    		break;
    		default:
    		{
    			cout<<"Incorrect entry";
    		}
    		break;
    	}
    
    	}
    }//here
    Please help

  2. #2
    Registered User
    Join Date
    Nov 2005
    Posts
    673
    because of your
    Code:
    do { }
    block. you never put a
    Code:
     while ( condition );
    . So you are missing a ";" in your code therefore it will not compile

  3. #3
    Massively Single Player AverageSoftware's Avatar
    Join Date
    May 2007
    Location
    Buffalo, NY
    Posts
    141
    You forgot the condition for your do loop.

    Ooops, someone beat me to it.

  4. #4
    Registered User
    Join Date
    May 2007
    Posts
    21
    lol, I went over it and over it and i can't believe I forgot that. Thank you both very much. And if anyone happens to read this, could you please answer my next question.

    How do I post a finished version of my game as a download file?
    Would I just upload it as a .cpp file?

    please help if you don't mind

  5. #5
    Registered User
    Join Date
    Nov 2005
    Posts
    673
    either upload the source, or upload a zip file with a .txt extension, or link to an external site( although I think this is frowned upon because of broken links)

  6. #6
    Registered User
    Join Date
    May 2006
    Posts
    903
    I'd suggest not uploading an executable file, for security concerns. Just upload the source file.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. An error is driving me nuts!
    By ulillillia in forum C Programming
    Replies: 5
    Last Post: 04-04-2009, 09:15 PM
  2. Using VC Toolkit 2003
    By Noobwaker in forum Windows Programming
    Replies: 8
    Last Post: 03-13-2006, 07:33 AM
  3. using c++ in c code
    By hannibar in forum C Programming
    Replies: 17
    Last Post: 10-28-2005, 09:09 PM
  4. pointer to array of objects of struct
    By undisputed007 in forum C++ Programming
    Replies: 12
    Last Post: 03-02-2004, 04:49 AM
  5. Couple C questions :)
    By Divx in forum C Programming
    Replies: 5
    Last Post: 01-28-2003, 01:10 AM