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

Started by
13 comments, last by Zakwayda 17 years, 5 months ago
problem solved! [Edited by - alway616 on November 25, 2006 6:38:53 PM]
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...
Whether you think you can or think you can’t, you’re probably right – Henry Ford
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
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.]
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
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]
"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.
ahhh il try removing that then

edit:
no effect... still the error is there
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
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)

This topic is closed to new replies.

Advertisement