473,378 Members | 1,498 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

expected ; before bool

134 100+
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=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;
}
}

}





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
Apr 28 '07 #1
4 8308
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"

Expand|Select|Wrap|Line Numbers
  1. bool Battle ()
  2. {
  3.  
  4.     int YourHealth;
  5.     int TheRatsHealth;
  6.     YourHealth=25;
  7.     TheRatsHealth=5;
  8.     char HurtRat;
  9. }
  10.  
  11. bool BattleRat ()
  12. {
  13.     cout <<"What would you like to do?";
  14.     cout <<"1.Hit The Rat";
  15.     cout <<"2.Kick The Rat";
  16.     cin >> HurtRat;
  17.     cin.ignore(20,'\n');
  18.     if (HurtRat == '1')
  19.     {
  20.         cout <<"You Hit The Rat";
  21.         TheRatsHealth=TheRatsHealth-1;
  22.         if TheRatsHealth<1
  23.         {
  24.             cout <<"You killed the Rat";
  25.             cin.get();
  26.             cin.ignore();
  27.             ImperialCity();
  28.         }
  29.     }
  30.     if (HurtRat == '2')
  31.     {
  32.         cout <<"You kick The Rat";
  33.         TheRatsHealth=TheRatsHealth-2;
  34.     }
  35. }
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.
Apr 28 '07 #2
lumpybanana247
134 100+
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"

Expand|Select|Wrap|Line Numbers
  1. bool Battle ()
  2. {
  3.  
  4.     int YourHealth;
  5.     int TheRatsHealth;
  6.     YourHealth=25;
  7.     TheRatsHealth=5;
  8.     char HurtRat;
  9. }
  10.  
  11. bool BattleRat ()
  12. {
  13.     cout <<"What would you like to do?";
  14.     cout <<"1.Hit The Rat";
  15.     cout <<"2.Kick The Rat";
  16.     cin >> HurtRat;
  17.     cin.ignore(20,'\n');
  18.     if (HurtRat == '1')
  19.     {
  20.         cout <<"You Hit The Rat";
  21.         TheRatsHealth=TheRatsHealth-1;
  22.         if TheRatsHealth<1
  23.         {
  24.             cout <<"You killed the Rat";
  25.             cin.get();
  26.             cin.ignore();
  27.             ImperialCity();
  28.         }
  29.     }
  30.     if (HurtRat == '2')
  31.     {
  32.         cout <<"You kick The Rat";
  33.         TheRatsHealth=TheRatsHealth-2;
  34.     }
  35. }
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
Apr 28 '07 #3
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.
Apr 28 '07 #4
lumpybanana247
134 100+
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=TheRatsHealth-1;

}
if (HurtRat == '2')
{
cout <<"You kick The Rat\n";
TheRatsHealth=TheRatsHealth-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=TheRatsHealth-1;

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

}

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

}
Apr 28 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: j. smith | last post by:
Hi, I need your help! Why does Borland Builder says E2293 ) expected at line 210 when using the fellowing line: virtual void Parse(const TCHAR* szValue) = 0;
13
by: Generic Usenet Account | last post by:
Compile the following snippet of code and run it. If the program spits out bat:bat instead of bat:zat, what would you say? Would you say that the compiler has a problem, or would you lay the...
4
by: Shailendra Batham | last post by:
Hi guys,Does any1 know what this error is all about, what I am trying to do is deserialize a XML, below is my code, let me know what I am doing wrongpublic class test{xin = "<?xml version='1.0'...
16
by: mfdatsw1 | last post by:
I need to be certain my application only runs once on a machine, and I implemented a solution using Mutex. The solution was posted many times, but one great link I found is...
6
by: Alex Buell | last post by:
#include <vector> #include <algorithm> #include <iostream> using namespace std; template <typename T> class LessThan { private:
2
by: fhasdkfhadlksfjhalsdkfh12 | last post by:
I've been working on a decryption program for another encryption program I made. It isn't finished, and when I try to compile it to test it, it gives me the error "expected unqualified-id before...
12
by: Fab | last post by:
Hi, I try to compile a 2 years old project (successfully compiled with g++ 3.3, if I correctly remember ). But get problems now with g++ -gcc 4.2.3 : #include <list> #include <hash_map>
1
by: lovecreatesbea... | last post by:
In the following function `HardwareStatusDb()', If its arguments are declared as type of `string', I get: main.cpp:5: error: expected initializer before ‘int’. The error disappears when those...
9
by: erictheone | last post by:
Ok so what I'm trying to do is create a trans location cipher. For those among us that don't know alot about cryptography it is a method for jumbling up letters to disguise linguistic...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.