Syntax Error

This is a discussion on Syntax Error within the C++ Programming forums, part of the General Programming Boards category; For some reason there is a syntax error at line 117 before +=. Code: //My Role-Playing Game #include <iostream.h> #include ...

  1. #1
    Rad gcn_zelda's Avatar
    Join Date
    Mar 2003
    Posts
    942

    Syntax Error

    For some reason there is a syntax error at line 117 before +=.

    Code:
    //My Role-Playing Game
    #include <iostream.h>
    #include <string>
    int main()
    {
    	float hp;
    	float dp;
    	float mp;
    	float fp;	
        float maxhp;
        float maxmp;
    	std::string weapon;
        std::string attack;
    	cout << "What is your name?" << endl;
    	std::string name;
    	cin >> name;
    	cout << "What is your race?" << endl;
    	cout << "Elf, Human, Orc" << endl;
    	std::string race;
        cin >> race;
    	cout << "Hello, " << name <<". Your race is " << race << endl;
    	if(race=="Elf")
    	{
    		maxhp, hp=105;
    		dp=20;
    		maxmp, mp=45;
    		fp=35;
    		weapon="Bow";
    	}
    	if(race=="Human")
    	{
    		maxhp, hp=115;
    		dp=23;
    		maxmp, mp=15;
    		fp=30;
    		weapon="Sword";
    	}
    	if(race=="Orc")
    	{
    		maxhp, hp=76;
    		dp=30;
    		maxmp, mp=19;
    		fp=42;
    		weapon="Axe";
    	}
    	cout << "Your weapon is " << weapon << endl;
    	cout << "You are in the middle of a deep forest when suddenly you are attacked by a wild boar. Do you... " << endl;
    	float enehp=40;
    	float enedp=5;
    	while(enehp >= 1)
    	{
            cout << "Attack, Run" << endl;
            float hurtene;
    		cin >> attack;
    		if(attack == "Attack")
    		{
    			hurtene = fp-enedp;
    			enehp -= hurtene;
    		    cout << "You did " << hurtene << " damage!!!" << endl;
    		}
    		if(attack == "Run")
    		{
    			cout << "You can't run from the battle!!!" << endl;
    		}
    	}
    	cout << "You killed the boar!" << endl;
    	cout << "You found boar meat!!!" << endl;
    	float boarmeat;
    	boarmeat+=1;
    	cout << "Mother: " << name << "!!!" << endl;
    	cout << "Mother: It's dinner time!!!" << endl;
    	cout << "You run to your house with the boar meat hanging over your shoulder" << endl;
    	cout << "Father: It's high time you learned to fight." << endl;
    	cout << name << ": If you say so." << endl;
    	cout << "A golem appeared!" << endl;
    	cout << "Father: First, choose an attack. Your choices are attack, magic, and run." << endl;
        enehp=65;
        enedp=10;
        float enefp;
        enefp=40;
        float hurtene;
        while(enehp >= 1)
        {
                    battlestart:
                    cin >> attack;
                    if(attack == "Attack")
                    {
                              hurtene=fp-enedp;
                              enehp-=hurtene;
                              cout << "You did " << hurtene << " damage!" << endl;
                    }
                    if(attack == "Magic")
                    {
                              cout << "Father: You can't yet use magic!" << endl;
                              cout << "Father: Pick something else!" << endl;
                              goto battlestart;
                    }
                    if(attack == "Run")
                    {
                              cout << "Father: Don't run! Not after you've come this far!" << endl;
                              cout << "Pick something else!" << endl;
                              goto battlestart;
                    }
                    //enemy's turn
                    float hurtyou;
                    hurtyou=enefp-dp;
                    hp-=hurtyou;
                    cout << "The enemy did " << hurtyou << " damage!!!" << endl;
                    if(hp <= 0)
                    {
                          cout << "You died" << endl;
                          cin.ignore();
                          cin.get();
                          return 0;
                    }
        }
        int exp+=25;
        cout << "You gained 25 exp!" << endl;
        cout << "Father: You see, " << name << ", when you destroy a monster, you will gain experience. If your experience grows to more than 100, you will gain a level and stats. " << endl;
        cout << "Now, go to bed and it will all be fine. " << endl;
        cout << "You went to bed" << endl;
        hp=maxhp;
        mp=maxmp;
        cout << "Mother: " << name << "!!!" << endl;
        cout << "You wake up and yell JUST A MINUTE!!!" << endl;
        cout << "You reach under your pillow and feel a spherical object." << endl;
        cout << "As you pull it out, you realize that it is a magical orb!" << endl;
        cout << "You learned [Glacier Ice]!!!" << endl;
        int glacierice=1;
        cout << name << "!!!. Hurry up or you'll be late for baseball practice!!!" << endl;
        cout << name << ": Mom! " << race << "s don't play baseball!" << endl;
        cout << "As you head downstairs, a pigmy toad flies out the window and attacks you. Do you..." << endl;
        enehp=120;
        enefp=30;
        enedp=15;
        while(enehp >= 1)
        {
                    cout << "Attack, Magic, Run" << endl;
                    std::string attack;
                    cin >> attack;
                    if(attack=="Attack")
                    {
                           hurtene=fp-enedp;
                           enehp-=hurtene;
                           cout << "You did " << hurtene << " damage!" << endl;
                    }
                    if(attack=="Magic")
                    {
                                      cout << "Which magic?" << endl;
                                      cout << "G-[Glacier Ice]" << endl;
                                      char choosemagic;
                                      cin >> choosemagic;
                                          if(choosemagic='G')
                                          {
                                                             enehp-=fp*2;
                                                             cout << "You did " << enefp*2 << " damage" << endl;
                                                             mp-=5;
                                          }
                     }
                     if(attack=="Run")
                     {
                                     cout << "You ran down stairs!!!" << endl;
                                     goto downstairs;
                     }
                     float hurtyou=enefp-dp;
                     hp-=hurtyou;
                     cout << "The enemy did " << hurtyou << " damage!" << endl;
                     if(hp <= 0)
                     {
                           cout << "You died" << endl;
                           cin.ignore();
                           cin.get();
                           return 0;
                     }
        }
        cout << "You gained 50 exp!" << endl;
        exp+=50;
        cout << "You ran downstairs to see your mom." << endl;
        downstairs:
        cout << "Mom: Your dad called. He says for you to meet him at the battle arena." << endl;
        cin.ignore();
        cin.get();
        return 0;
        }
    Help!!!

  2. #2
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    Do you mean this line?

    int exp+=25;

    Declare exp first.

    int exp = 0;
    exp+=25;

    Otherwise,

    int exp=25;

    Kuphryn

  3. #3
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109
    Code:
    int exp+=25;
    you cannot do this line. += is like
    Code:
    exp = exp + 25;
    it adds to the current number in exp. I haven't read through your code to see if you have another exp that you are trying to add to, but if you don't, remove the +.

    edit: kuphryn beat me.
    Last edited by alpha; 03-27-2003 at 07:07 PM.

  4. #4
    Rad gcn_zelda's Avatar
    Join Date
    Mar 2003
    Posts
    942
    but thats what i want! exp=exp + 25!

  5. #5
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109
    then do what kuphryn said in the first part of his post.

  6. #6
    Geo Geo Geo-Fry
    Join Date
    Feb 2003
    Posts
    116
    i think what they are trying to say is that you are declaring the int exp and modifying it at the same time. you can do exp+=25;, and you can do int exp;, but you cant do int exp+=25. declare it first and then add 25 to it. thats what i think they meant but i could be way off
    "You can lead a man to Congress, but you can't make him think."
    "The Grand Old Duke of York
    -He had ten thousand men.
    -His case comes up next week."
    "Roses are red, violets are blue, I'm schizophrenic, and so am I."
    "A computer once beat me at chess, but it was no match for me at kick boxing."
    "More and more of our imports are coming from overseas."
    --George W. Bush
    "If it weren't for electricity, we'd all be wacthing TV by candlelight."
    --George W. Bush

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  2. Testing some code, lots of errors...
    By Sparrowhawk in forum C Programming
    Replies: 48
    Last Post: 12-15-2008, 04:09 AM
  3. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  4. ras.h errors
    By Trent_Easton in forum Windows Programming
    Replies: 8
    Last Post: 07-15-2005, 11:52 PM
  5. Linking error
    By DockyD in forum C++ Programming
    Replies: 10
    Last Post: 01-20-2003, 05:27 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21