need help, don't know how to fix this error
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:
That should solve your problem, hopefully...
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...
Quote:Original post by alway616if (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:
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.]
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
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.
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.
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
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
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement