Jump to content
  • Advertisement
Sign in to follow this  
alway616

need help, don't know how to fix this error

This topic is 4257 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement
I think you need to make a function prototype. you can do this by putting:

int attack();

before your "main" and secondly when you call the function delete the void, so your coed should be like:

#include <iosteam>

int attack();

int main{
// Do stuff here
if(input == 'a')
attack();
return 0;
}

int attack(){
// Attack stuff here
}



That should solve your problem, hopefully...

Share this post


Link to post
Share on other sites
Quote:
Original post by alway616
   if (input == 'a')
void attack();
return 0;
}

int attack() <------------------------------line with errors
{

Probably what's confusing the compiler. There may be other errors outside of the snippet you posted. If that change doesn't fix things post more code, inside [source] tags.

Σnigma

Share this post


Link to post
Share on other sites
The only thing I can say for sure is that in this bit of code:
if (input == 'a')
void attack();
return 0;
}
You're missing an opening brace, and 'void' is an error (I'm not sure what your intent is in including it there).

Beyond that, you'll probably need to post in its entirety the function from which the above code is taken.

[Edit: Reading the above posts, I see you may not be missing an opening brace. However, without seeing the entire function we can't really tell for sure.]

Share this post


Link to post
Share on other sites
the void is there because originaly the function was void not int, and the problem was there before i changed it, infact, thats why i changed it


here, ill post the entire program:

#include <iostream>
#include <string>

using namespace std;




int hitpoints = 100;
int evasion = 10;
int power = 10;
int defense = 10;
int accuracy = 10;
int money = 100;
int area = 2;
int xp = 1;
int level = 1;

int attack();
int main()
{
cout<<"Greetings Gladiator. Welcome to Arena Quest."<<endl;
while(1<2)
{
char input;
cin >> input;
if (input == 'a')
int attack();
return 0;
}






int attack()
{
while (hitpoints > 0 && enhitpoints > 0)
{
t=0;
while (t<500)
t=+1;
accuracy-1/4*enevasion=hitchance;
power-1/4*endefense=hitpower;
srand(time(0));
int percent=rand();
int hitmiss=percent%100;
if(hitmiss<=hitchance)
{
srand(time(0));
percent+rand();
int hitstr=percent%100;
int atten=hitpower*hitstr;
}
else
int atten = 0;
enhitpoints=-atten;
cout<<"You dealt"<<atten<<"damage. The enemy has"<<enhitpoints<<"hitpoints left."<<endl;
xp=xp+2*atten;


int enhitchance=enaccuracy-1/4*evasion
int enhitpower=enpower-1/4&defense
srand(time(0));
percent = rand();
hitmiss=percent%100;
if (enhitchance>=hitmiss)
{
srand(time(0));
percent=rand();
int enhitstr=percent
int enatt=enhitpower*enhitstr;
}
else
int enatt=0;
hitpoints=-enatt;
cout<<"The enemy did"<<enatt<<"damage. You have"<<hitpoints<<"hitpoints left."<<endl;
}
return 0;
}






there, as i said, it is not complete, but other than some unidentifyed variables in the attack function, it is fairly workable

Share this post


Link to post
Share on other sites
Quote:
Original post by Enigma
If that change doesn't fix things post more code, inside [source] tags.


[Edited by - jyk on November 26, 2006 1:55:50 AM]

Share this post


Link to post
Share on other sites
"void attack();"

That doesn't look right to me at all. What's the void supposed to be doing? You only right the return type when you declare or define the function, not call it.

Edit: OMG I am soo slow.

However, I've noticed that you just put 'int' where you had 'void'. There shouldn't be anything there.

Share this post


Link to post
Share on other sites
You are missing a closing brace } after int attack();, which should be attack(); as someone said.
Missing bracers will confuse the compiler big time, and generate lots of "fake" errors.

Im sure you are aware of the fact that the loop while(1 < 2) will never end, so you might as well use while(1) and get the same effect :D

Share this post


Link to post
Share on other sites
oh thanks alot! it worked
how blatantly obvious to...
now the only errors are the ones that are supposed to be there (the undeclared variables)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!