error 2062: type 'void' unexpected.

this is supposed to draw a random 50x50 square on the screen the have the user guess the center point of the square and draw a circle with the radius of 25, if they get it right it ends, if not it clears and repeats.

I can not seem to figure out why I'm getting the error c2062 ON LINE 108 here is what I've got for code, hopefully someone can answer soon since i have to turn this assignment in tonight!

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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#include "DarkGDK.h"

//Constants for screen size
const int SCREEN_W = 640;
const int SCREEN_H = 480;

//Constant radius
const int RADIUS = 25;

//Variables for Width and Height
const int WIDTH = 50;
const int HEIGHT = 50;

//Function prototype
void setup();
void drawSquare(int, int);
void drawCircle(int, int);
void playGame();
void endGame();

//Main entry point for the application
void DarkGDK ()
{
	setup();
	playGame();
	endGame();
}

void setup()
{
	//Sets the window and title seed.
	dbSetWindowTitle("Round Peg in a Square Hole");

	//Seed the random number generator
	int seed = dbTimer();
	dbRandomize( dbTimer() );	
	

void drawSquare(int centerX, int centerY);
{
	//Square Variables
	int centerX = dbRND(SCREEN_W);
	int centerY = dbRND(SCREEN_H);
	int x1 = centerX - WIDTH/ 2;
	int y1 = centerY - HEIGHT/ 2;
	int x2 = centerX + WIDTH/ 2;
	int y2 = centerY + HEIGHT/ 2;
	
	//Drawing the square
	dbLine(x1, y1, x2, y1); // Top
	dbLine(x2, y1, x2, y2); // Right
	dbLine(x2, y2, x1, y2); // Bottom
	dbLine(x1, y2, x1, y1); // Left

}
void drawCircle(int centerX, int CenterY);
{
	int centerX, centerY;
	dbPrint("Enter your guess of the x coordinate.");
	centerX= atoi(dbInput());

	dbPrint("Enter your guess for the y coordinate.");
	centerY= atoi(dbInput());
	
	//Draw circle
	dbCircle(centerX, centerY, RADIUS);
}
/* The playGame function prompts the user to guess the XY coordinates of the square
then draws a circle around the guessed coordinates.This repeats until the user gets 
it right */
void playGame();
{
	//Variables for the center points of the circle and square
	int randomX = 0;
	int randomY = 0;
	int circleX = 0;
	int circleY = 0;

	//Repeat the process until user guesses correctly
	do
	{
		//Clear the screen
		dbCLS();

		//Generate a random center point.
		randomX = WIDTH / 2 + dbRND(SCREEN_W - WIDTH);
		randomY = HEIGHT / 2 + dbRND(SCREEN_H - HEIGHT);

		//Draw square at random location
		drawSquare(randomX, randomY);

		//Prompt user the guess square's center point.
		dbPrint("Guess the X and Y values of the square's center point.");
		//Get the user's input for the X value.
		dbPrint("Enter your guess for the X value.");
		circleX = atoi(dbInput());
		//Get the user's input for the Y value.
		dbPrint("Enter your guess for the Y value.");
		circleY = atoi(dbInput());
		//Wait for user to press a key.
		dbWaitKey();
		while (circleX != randomX && circleY != randomY);
}


// The endGame function clears the screen and displays a message if the user gets the answer correct.

	void endGame();
	{
		//Clear the screen.
		dbCLS();
		// Increase the size of the text to 26 point.
		dbSetTextSize(26);
		// Display a congratulations message
		dbCenterText(SCREEN_W / 2, SCREEN_H / 2,
		"CONGRATULATIONS!");
		// Wait for one second, then exit.
		dbWait(1000);
		}

	}
}
Last edited on
You're missing a } before void endGame. Proper formatting would help you notice that.
for whatever reason that is how it copied and pasted. i have tried adding } before void endGame and get multiple syntax errors.
closed account (zb0S216C)
You're missing a closing brace at the end of ::setup( ).

Wazzak
That results in multiple errors as well..

Error 1 error C2447: '{' : missing function header (old-style formal list?)

Error 2 error C2447: '{' : missing function header (old-style formal list?)

Error 3 error C2447: '{' : missing function header (old-style formal list?)

Error 4 error C2059: syntax error : '}'

Error 5 error C2143: syntax error : missing ';' before '}'

Error 6 error C2059: syntax error : '}'
closed account (zb0S216C)
Remove the semi-colon after ::endGame( )'s parameter list where it's defined.

Wazzak
Last edited on
i guess I am really not understanding this at all. I remove the semi colon after void endGame and add the } at the end of setup and i end up with:

Error 1 error C2447: '{' : missing function header (old-style formal list?

Error 2 error C2447: '{' : missing function header (old-style formal list?)

Error 3 error C2447: '{' : missing function header (old-style formal list?)

Error 4 error C2059: syntax error : '}'

Error 5 error C2143: syntax error : missing ';' before '}'

Error 6 error C2059: syntax error : '}'

i am beginning to feel really dumb here :(
closed account (zb0S216C)
Here's what you need to do:

1) Format your code with [code_][/code] tags (without the underscore)
2) Using the line numbers as a reference, point out the line (s) where the compiler is stopping. It's hard to read your code without formatting.

Wazzak
Here:
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#include "DarkGDK.h"

//Constants for screen size
const int SCREEN_W = 640;
const int SCREEN_H = 480;

//Constant radius
const int RADIUS = 25;

//Variables for Width and Height
const int WIDTH = 50;
const int HEIGHT = 50;

//Function prototype
void setup();
void drawSquare(int, int);
void drawCircle(int, int);
void playGame();
void endGame();

//Main entry point for the application
void DarkGDK ()
{
setup();
playGame();
endGame();
}

void setup()
{
//Sets the window and title seed.
dbSetWindowTitle("Round Peg in a Square Hole");

//Seed the random number generator
int seed = dbTimer();
dbRandomize( dbTimer() );


void drawSquare(int centerX, int centerY);
{
//Square Variables
int centerX = dbRND(SCREEN_W);
int centerY = dbRND(SCREEN_H);
int x1 = centerX - WIDTH/ 2;
int y1 = centerY - HEIGHT/ 2;
int x2 = centerX + WIDTH/ 2;
int y2 = centerY + HEIGHT/ 2;

//Drawing the square
dbLine(x1, y1, x2, y1); // Top
dbLine(x2, y1, x2, y2); // Right
dbLine(x2, y2, x1, y2); // Bottom
dbLine(x1, y2, x1, y1); // Left

}
void drawCircle(int centerX, int CenterY);
{
int centerX, centerY;
dbPrint("Enter your guess of the x coordinate.");
centerX= atoi(dbInput());

dbPrint("Enter your guess for the y coordinate.");
centerY= atoi(dbInput());

//Draw circle
dbCircle(centerX, centerY, RADIUS);
}
/* The playGame function prompts the user to guess the XY coordinates of the square
then draws a circle around the guessed coordinates.This repeats until the user gets
it right */
void playGame();
{
//Variables for the center points of the circle and square
int randomX = 0;
int randomY = 0;
int circleX = 0;
int circleY = 0;

//Repeat the process until user guesses correctly
do
{
//Clear the screen
dbCLS();

//Generate a random center point.
randomX = WIDTH / 2 + dbRND(SCREEN_W - WIDTH);
randomY = HEIGHT / 2 + dbRND(SCREEN_H - HEIGHT);

//Draw square at random location
drawSquare(randomX, randomY);

//Prompt user the guess square's center point.
dbPrint("Guess the X and Y values of the square's center point.");
//Get the user's input for the X value.
dbPrint("Enter your guess for the X value.");
circleX = atoi(dbInput());
//Get the user's input for the Y value.
dbPrint("Enter your guess for the Y value.");
circleY = atoi(dbInput());
//Wait for user to press a key.
dbWaitKey();
while (circleX != randomX && circleY != randomY);
}


// The endGame function clears the screen and displays a message if the user gets the answer correct.

void endGame();
{
//Clear the screen.
dbCLS();
// Increase the size of the text to 26 point.
dbSetTextSize(26);
// Display a congratulations message
dbCenterText(SCREEN_W / 2, SCREEN_H / 2,
"CONGRATULATIONS!");
// Wait for one second, then exit.
dbWait(1000);
}

}
} 

I personaly can't help either without seeing the proper formatting!
edited original post, thank you for that. As it is above i only get the error C2062: type 'void' unexpected at line 108
add }s before lines 37 and 102.
remove ;s from lines 39, 56, 71, 108.
remove the two }s at the end of the file.
ok did that and now get

error C2082: redefinition of formal parameter 'centerX' line 42

error C2082: redefinition of formal parameter 'centerY' line 43

error C2082: redefinition of formal parameter 'centerX' line 58
closed account (zb0S216C)
On the lines you stated, you're redeclaring centerX and centerY. Remove the proceeding int from each of those lines.

Wazzak
Last edited on
ok I am getting rather frustrated with this now, i remove the int and now get

error C2065:'centerY': undeclared identifier line 58

error C2065:'centerY': undeclared identifier line 63

error C2065:'centerY': undeclared identifier line 66
closed account (zb0S216C)
Do the same for them, too.

Wazzak
i removed the int centerX, centerY from line 56 and it compiled with no errors, but i can not see a circle for whatever reason. i have done a program to draw a circle, ellipse, and dot to no avail can only see lines and boxes. thats kind of annoying as well. so what i have now is:

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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#include "DarkGDK.h"

//Constants for screen size
const int SCREEN_W = 640;
const int SCREEN_H = 480;

//Constant radius
const int RADIUS = 25;

//Variables for Width and Height
const int WIDTH = 50;
const int HEIGHT = 50;

//Function prototype
void setup();
void drawSquare(int, int);
void drawCircle(int, int);
void playGame();
void endGame();

//Main entry point for the application
void DarkGDK ()
{
	setup();
	playGame();
	endGame();
}

void setup()
{
	//Sets the window and title seed.
	dbSetWindowTitle("Round Peg in a Square Hole");

	//Seed the random number generator
	int seed = dbTimer();
	dbRandomize( dbTimer() );	
}

void drawSquare(int centerX, int centerY)
{
	//Square Variables
	centerX = dbRND(SCREEN_W);
	centerY = dbRND(SCREEN_H);
	int x1 = centerX - WIDTH/ 2;
	int y1 = centerY - HEIGHT/ 2;
	int x2 = centerX + WIDTH/ 2;
	int y2 = centerY + HEIGHT/ 2;
	
	//Drawing the square
	dbLine(x1, y1, x2, y1); // Top
	dbLine(x2, y1, x2, y2); // Right
	dbLine(x2, y2, x1, y2); // Bottom
	dbLine(x1, y2, x1, y1); // Left

}
void drawCircle()
{
	int centerX, centerY;

	dbPrint("Enter your guess of the x coordinate.");
	centerX= atoi(dbInput());

	dbPrint("Enter your guess for the y coordinate.");
	centerY= atoi(dbInput());
	
	//Draw circle
	dbCircle(centerX, centerY, RADIUS);
}
/* The playGame function prompts the user to guess the XY coordinates of the square
then draws a circle around the guessed coordinates.This repeats until the user gets 
it right */
void playGame()
{
	//Variables for the center points of the circle and square
	int randomX = 0;
	int randomY = 0;
	int circleX = 0;
	int circleY = 0;

	//Repeat the process until user guesses correctly
	do
	{
		//Clear the screen
		dbCLS();

		//Generate a random center point.
		randomX = WIDTH / 2 + dbRND(SCREEN_W - WIDTH);
		randomY = HEIGHT / 2 + dbRND(SCREEN_H - HEIGHT);

		//Draw square at random location
		drawSquare(randomX, randomY);

		//Prompt user the guess square's center point.
		dbPrint("Guess the X and Y values of the square's center point.");
		//Get the user's input for the X value.
		dbPrint("Enter your guess for the X value.");
		circleX = atoi(dbInput());
		//Get the user's input for the Y value.
		dbPrint("Enter your guess for the Y value.");
		circleY = atoi(dbInput());
		//Wait for user to press a key.
		dbWaitKey();
	}
		while (circleX != randomX && circleY != randomY);
}


// The endGame function clears the screen and displays a message if the user gets the answer correct.
	
void endGame()
	{
		//Clear the screen.
		dbCLS();
		// Increase the size of the text to 26 point.
		dbSetTextSize(26);
		// Display a congratulations message
		dbCenterText(SCREEN_W / 2, SCREEN_H / 2,
		"CONGRATULATIONS!");
		// Wait for one second, then exit.
		dbWait(1000);
		}
Topic archived. No new replies allowed.