void issues with ';'

closed account (LAfSLyTq)
no matter what i do i cant seem to get rid of this thing where no matter where i place my void namephase() it always has an error saying it expected a ';' please help!
closed account (zb0S216C)
Can you post the relevant code? That's the code up to the line where the error occurs.

Wazzak
What is a void namephase() ?
closed account (LAfSLyTq)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <iostream>
#include <string>
#include <ctime>
#include <cstdlib>
using namespace std;

void battlephase;
void namephase;

class Player;

class Player
{
public:

	int health;
	int exp;
	int level;
	int atk;
	Player (bool Player)
	{
		health = 10;
		level = 1;
		exp = 0;
		atk = 10;
	}	
};

int main()
{
	Player P(true);

	int damageDealt;

	char name[10];

	char Action;

	int money;
	money=1000;

	cout<<"\tWelcome to A Warrior Game!\n\tHere is where your adventure will begin.\n\tEnjoy!"<<endl;
		
	void namephase()
	{
		cout<<"\n\nEnter Your name."<<endl;
	cin>>name;
	cout<<"Your name is "<<name<<"?\n 1=Yes 2=No"<<endl;
	cin>>Action;
	if(Action=='1')
	{
		cout<<"Very well\n"<<endl;
	}
	if(Action=='2')
	{
		cout<<"What is your name?"<<endl;
		cin>>name;
		cout<<"Your name is now "<<name<<"!\n"<<endl;
	}
	}
closed account (zb0S216C)
Function definitions cannot appear in other function definitions; only prototypes are allowed to be within function definitions.

Wazzak
Last edited on
void battlephase;

What the bejesus is this trying to do? You cannot create an object of type void. It's nonsensical. Is this meant to be a function declaration?

void battlephase();
Last edited on
closed account (LAfSLyTq)
i dont understand what i am supposed to change.. please help, i know that my code is wrong, how am i supposed to rewrite it?
closed account (zb0S216C)
Invader2010 wrote:
1
2
void battlephase;
void namephase;

...are not valid declarations of any kind. If they are supposed to be function prototypes, then they will need be:

1
2
void battlephase(void); // 'void' is optional
void namephase(void);

However, if they are object declarations, then they aren't valid. void translates to either nothing or unknown; depending on the context.

Wazzak
Last edited on
closed account (LAfSLyTq)
okay, i changed that and i still get the ';' error... =[
closed account (zb0S216C)
Have you removed namephase()'s definition from main()? Also, can you update your code so we know where you stand.

Wazzak
Just take that function outside the main(), like that

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <iostream>
#include <string>
#include <ctime>
#include <cstdlib>
using namespace std;

void battlephase;
void namephase;

class Player;

class Player
{
public:

	int health;
	int exp;
	int level;
	int atk;
	Player (bool Player)
	{
		health = 10;
		level = 1;
		exp = 0;
		atk = 10;
	}	
};
	void namephase()
	{
		cout<<"\n\nEnter Your name."<<endl;
	cin>>name;
	cout<<"Your name is "<<name<<"?\n 1=Yes 2=No"<<endl;
	cin>>Action;
	if(Action=='1')
	{
		cout<<"Very well\n"<<endl;
	}
	if(Action=='2')
	{
		cout<<"What is your name?"<<endl;
		cin>>name;
		cout<<"Your name is now "<<name<<"!\n"<<endl;
	}
	}
int main()
{
	Player P(true);

	int damageDealt;

	char name[10];

	char Action;

	int money;
	money=1000;

	cout<<"\tWelcome to A Warrior Game!\n\tHere is where your adventure will begin.\n\tEnjoy!"<<endl;
	void namephase(); //here you call that function
}
Something else I'd like to note is that you cannot define your functions* in main. You need to do that outside, which would mean adding a few arguments to your function and moving it outside of main. :)

EDIT: Ninjas.

*Lambda functions can and should be defined inside a function, but I don't see why you'd need a lambda function here.

-Albatross
Last edited on
closed account (LAfSLyTq)
okay here is my current code.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include <iostream>
#include <string>
#include <ctime>
#include <cstdlib>
using namespace std;

void battlePhase()
{
cout << endl << "\nWhat do you want to do? ";
cin >> Action;
if ( Action == "Attack" || Action == "attack" )
{
cout << endl << name << " attacked " << "enemy" << " for " << P.atk << endl;
damageDealt = P.atk;
if ( damageDealt < 0 )
{
damageDealt = 0;
}
if ( damageDealt == 0 )
{
cout << "\nNo damage!";
}
if ( damageDealt > 0 )
{
cout << "enemy" << " took " << damageDealt << " damage!";
E.Hp = E.Hp - damageDealt;
}
}
else
{
cout << "\nThat isn't an action! Try typing 'attack'.";
battlePhase();
}
}
	 
void namephase()
	{
		cout<<"\n\nEnter Your name."<<endl;
	cin>>name;
	cout<<"Your name is "<<name<<"?\n 1=Yes 2=No"<<endl;
	cin>>Action;
	if(Action=='1')
	{
		cout<<"Very well\n"<<endl;
	}
	if(Action=='2')
	{
		cout<<"What is your name?"<<endl;
		cin>>name;
		cout<<"Your name is now "<<name<<"!\n"<<endl;
	}
	}

class Player;

class Player
{
public:

	int health;
	int exp;
	int level;
	int atk;
	Player (bool Player)
	{
		health = 10;
		level = 1;
		exp = 0;
		atk = 10;
	}	
};


int main()
{
	Player P(true);
	Boar E(true);
	Gunthor G(true);

	int damageDealt;

	char name[10];

	char Action;

	int money;
	money=1000;

	cout<<"\tWelcome to A Warrior Game!\n\tHere is where your adventure will begin.\n\tEnjoy!"<<endl;
	namephase;


thanks alot, this worked! but, now i have a new problem, half the things at the top arent defined until later so it gives me more errors....
closed account (zb0S216C)
You'll need to pass the objects you need to the function when you invoke (call) it. For example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
void Function(int pValue);

int main(void)
{
    int My_int(0);
    
    // Call my function and give it 'My_int'
    ::Function(My_int);

    // The '::' means the identifier following it resides within the
    // global namespace.

    return(0);
}

void Function(int pValue)
{
    //...
}

When ::Function() is called, My_int is copied into pValue of ::Function(). This is called passing by value. Modifications made to pValue will not affect My_int because it's a copy. However, by looking at your code, you'll need the functionality of references[1], or you'll never get anything done.

References:
[1] http://www.cprogramming.com/tutorial/references.html


Wazzak
Last edited on
closed account (LAfSLyTq)
thanks, but i am not understand what i am supposed to change. can you give me a better example within my code please?
However, by looking at your code, you'll need the functionality of references, or you'll never get anything done.


Well even with references he won't get anything done. He is declaring variables in main but using them in the functions at the top of the source so he will just keep getting errors. Tried writing up a 'fix' for the errors, but keep losing my place using his existing code.
Last edited on by closed account z6A9GNh0
closed account (zb0S216C)
BHXSpecter: That's the whole idea of prameters. What he/she needs to do is add the appropriate parameters, replace all references to the objects within main() with the corresponding parameters, then call the function(s). Global variables are not condoned by many.

Wazzak
@Framework:
Yes, I know, I understand references better than pointers to be honest. He may not know parameters (I never assume anyone knows even the basics of the language). References will fix it the functions, but still going to have errors after that.

1
2
3
4
Player P(true);
Boar E(true);
Gunthor G(true);


According to his code only the player class is defined so Boar and Gunthor will return errors (unless I missed that part of his code too). His code makes me feel he is trying too much at once and getting overwhelmed on it.
Last edited on by closed account z6A9GNh0
closed account (LAfSLyTq)
i probably am trying too much at once. but i dont know what i am supposed to do so i end up looking up a bunch of shit and i probably screwed myself on it.
Yeah, I figured that was the problem. I still am the same way with more advanced things like memory allocation and pointers still lose me. Not to mention linked lists, stacks, queue, heap, etc. If you haven't yet, just go through the lessons here on the site as they are good. Then maybe look into getting a book or two (I have The C++ Programming Language by Bjarne Stroustrup and C++ Primer). Don't give up on this, but it is better to start with tutorials and such to learn C++ basics, then if you want to make a game move onto Allegro (http://www.allegro.cc ), SDL(http://www.libsdl.org ), or SFML (http://www.sfml-dev.org ). Then you can move to XNA or OpenGL. If you just want to program then you could learn Qt and do GUI programming. Then of course you get into scripting languages like Python, Perl, Lua, Ruby, etc. C++ is a great starting point for programming, just have to find the right resources (this site and the tutorials being one such resource).
Last edited on by closed account z6A9GNh0
Topic archived. No new replies allowed.