expected ; before bool

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lumpybanana247
    New Member
    • Apr 2007
    • 134

    expected ; before bool

    I have this script....



    #include "Library.h"
    bool Battle ()
    {

    int YourHealth;
    int TheRatsHealth;
    YourHealth=25;
    TheRatsHealth=5 ;
    char HurtRat;


    bool BattleRat ()
    {
    cout <<"What would you like to do?";
    cout <<"1.Hit The Rat";
    cout <<"2.Kick The Rat";
    cin >> HurtRat;
    cin.ignore(20,' \n');
    if (HurtRat == '1')
    {
    cout <<"You Hit The Rat";
    TheRatsHealth=T heRatsHealth-1;
    if TheRatsHealth<1
    {
    cout <<"You killed the Rat";
    cin.get();
    cin.ignore();
    ImperialCity();
    }
    }
    if (HurtRat == '2')
    {
    cout <<"You kick The Rat";
    TheRatsHealth=T heRatsHealth-2;
    }
    }

    }





    and the error messages are

    Battle.cpp In function `bool Battle()':
    Battle.cpp expected primary-expression before "bool"
    Makefile.win [Build Error] [Battle.o] Error 1
    Battle.cpp expected `;' before "bool"

    i cant figure out how to fix this.

    if somebody knows, your help is appreciated---and if u have an idea on a diffenrt way to do this
  • cbbibleboy
    New Member
    • Apr 2007
    • 29

    #2
    The problem is that you're trying to declare one function in another. It seems like something someone might do if they're transferring from one programming language to another. I don't know if C/C++ is your first language, but you cannot do that in C. Rather, you should do:

    #include "Library.h"

    Code:
    bool Battle ()
    {
    
    	int YourHealth;
    	int TheRatsHealth;
    	YourHealth=25;
    	TheRatsHealth=5;
    	char HurtRat;
    }
    
    bool BattleRat ()
    {
    	cout <<"What would you like to do?";
    	cout <<"1.Hit The Rat";
    	cout <<"2.Kick The Rat";
    	cin >> HurtRat;
    	cin.ignore(20,'\n');
    	if (HurtRat == '1')
    	{
    		cout <<"You Hit The Rat";
    		TheRatsHealth=TheRatsHealth-1;
    		if TheRatsHealth<1
    		{
    			cout <<"You killed the Rat";
    			cin.get();
    			cin.ignore();
    			ImperialCity();
    		}
    	}
    	if (HurtRat == '2')
    	{
    		cout <<"You kick The Rat";
    		TheRatsHealth=TheRatsHealth-2;
    	}
    }
    Also, for code clarification, you should be tabbing-in things. Furthermore, you will get more errors because your functions aren't returning values, yet you say they should return 'bool's. I'm not exactly sure what you're trying to to, but I can help if you need more.

    Comment

    • lumpybanana247
      New Member
      • Apr 2007
      • 134

      #3
      Originally posted by cbbibleboy
      The problem is that you're trying to declare one function in another. It seems like something someone might do if they're transferring from one programming language to another. I don't know if C/C++ is your first language, but you cannot do that in C. Rather, you should do:

      #include "Library.h"

      Code:
      bool Battle ()
      {
      
      	int YourHealth;
      	int TheRatsHealth;
      	YourHealth=25;
      	TheRatsHealth=5;
      	char HurtRat;
      }
      
      bool BattleRat ()
      {
      	cout <<"What would you like to do?";
      	cout <<"1.Hit The Rat";
      	cout <<"2.Kick The Rat";
      	cin >> HurtRat;
      	cin.ignore(20,'\n');
      	if (HurtRat == '1')
      	{
      		cout <<"You Hit The Rat";
      		TheRatsHealth=TheRatsHealth-1;
      		if TheRatsHealth<1
      		{
      			cout <<"You killed the Rat";
      			cin.get();
      			cin.ignore();
      			ImperialCity();
      		}
      	}
      	if (HurtRat == '2')
      	{
      		cout <<"You kick The Rat";
      		TheRatsHealth=TheRatsHealth-2;
      	}
      }
      Also, for code clarification, you should be tabbing-in things. Furthermore, you will get more errors because your functions aren't returning values, yet you say they should return 'bool's. I'm not exactly sure what you're trying to to, but I can help if you need more.

      I tried that and now it says that all of the things in 'bool' battle are undeclared. i dont kbow what you mean by tabbing in either.
      for ur info, its supposed to be like a fight with the rat (not finished of coarse) but i couldent ecven get it so only me hitting the rat would work.
      thanks

      Comment

      • cbbibleboy
        New Member
        • Apr 2007
        • 29

        #4
        Should your code really be in two functions? It does not appear so to me.

        Notice the difference between your first code and when I reformatted it. Notice how it's not all lined up against the left side. That's what I meant by tabbing-in. By tabbing lines in, code is much easier to read and debug.

        Comment

        • lumpybanana247
          New Member
          • Apr 2007
          • 134

          #5
          thanks for ur help. this is how i made it work (ill put it in quotes)
          #include "Library.h"

          bool Battle ()
          {
          int YourHealth;
          int TheRatsHealth;
          char HurtRat;
          YourHealth=25;
          TheRatsHealth=5 ;


          cout <<"What would you like to do?\n";
          cout <<"1.Hit The Rat\n";
          cout <<"2.Kick The Rat\n";

          //choose what to do
          cin >> HurtRat;
          cin.ignore(20,' \n');
          if (HurtRat == '1')
          {
          cout <<"You Hit The Rat\n";
          TheRatsHealth=T heRatsHealth-1;

          }
          if (HurtRat == '2')
          {
          cout <<"You kick The Rat\n";
          TheRatsHealth=T heRatsHealth-2;

          }

          if (TheRatsHealth< 1)
          {
          cout <<"You killed the Rat";
          cin.get();
          cin.ignore();
          ImperialCity();
          }
          else
          {}

          cout <<"What would you like to do?\n";
          cout <<"1.Hit The Rat\n";
          cout <<"2.Kick The Rat\n";


          cin >> HurtRat;
          cin.ignore(20,' \n');
          if (HurtRat == '1')
          {
          cout <<"You Hit The Rat\n";
          TheRatsHealth=T heRatsHealth-1;

          }
          if (HurtRat == '2')
          {
          cout <<"You kick The Rat\n";
          TheRatsHealth=T heRatsHealth-4;

          }

          if (TheRatsHealth< 1)
          {
          cout <<"You killed the Rat";
          cin.get();
          cin.ignore();
          ImperialCity();
          }

          }

          Comment

          Working...