Error Messages

I am getting the following error messages when I compile my code. Can someone help me out? Here is the error messages:

1>------ Build started: Project: Week9Assignment, Configuration: Debug Win32 ------
1>Compiling...
1>Week9Assignment.cpp
1>c:\wxwidgets-2.8.8\week9assignment\week9assignment\week9assignment.cpp(91) : error C2146: syntax error : missing ';' before identifier 'get_name'
1>c:\wxwidgets-2.8.8\week9assignment\week9assignment\week9assignment.cpp(91) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\wxwidgets-2.8.8\week9assignment\week9assignment\week9assignment.cpp(91) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\wxwidgets-2.8.8\week9assignment\week9assignment\week9assignment.cpp(91) : warning C4183: 'get_name': missing return type; assumed to be a member function returning 'int'
1>c:\wxwidgets-2.8.8\week9assignment\week9assignment\week9assignment.cpp(97) : error C2143: syntax error : missing ')' before 'constant'
1>c:\wxwidgets-2.8.8\week9assignment\week9assignment\week9assignment.cpp(97) : error C2143: syntax error : missing ';' before 'constant'
1>c:\wxwidgets-2.8.8\week9assignment\week9assignment\week9assignment.cpp(97) : error C2059: syntax error : ')'
1>c:\wxwidgets-2.8.8\week9assignment\week9assignment\week9assignment.cpp(97) : error C2238: unexpected token(s) preceding ';'
1>c:\wxwidgets-2.8.8\week9assignment\week9assignment\week9assignment.cpp(103) : error C2061: syntax error : identifier 'string'
1>c:\wxwidgets-2.8.8\week9assignment\week9assignment\week9assignment.cpp(105) : error C2146: syntax error : missing ';' before identifier 'name'
1>c:\wxwidgets-2.8.8\week9assignment\week9assignment\week9assignment.cpp(105) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\wxwidgets-2.8.8\week9assignment\week9assignment\week9assignment.cpp(105) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\wxwidgets-2.8.8\week9assignment\week9assignment\week9assignment.cpp(248) : error C2143: syntax error : missing ';' before '-'
1>c:\wxwidgets-2.8.8\week9assignment\week9assignment\week9assignment.cpp(248) : warning C4552: '+' : operator has no effect; expected operator with side-effect
1>c:\wxwidgets-2.8.8\week9assignment\week9assignment\week9assignment.cpp(279) : error C2065: 'name' : undeclared identifier
1>c:\wxwidgets-2.8.8\week9assignment\week9assignment\week9assignment.cpp(284) : error C2143: syntax error : missing ')' before 'constant'
1>c:\wxwidgets-2.8.8\week9assignment\week9assignment\week9assignment.cpp(284) : error C2143: syntax error : missing ';' before 'constant'
1>c:\wxwidgets-2.8.8\week9assignment\week9assignment\week9assignment.cpp(284) : error C2761: 'void Player::set_level(int)' : member function redeclaration not allowed
1>c:\wxwidgets-2.8.8\week9assignment\week9assignment\week9assignment.cpp(284) : error C2059: syntax error : ')'
1>c:\wxwidgets-2.8.8\week9assignment\week9assignment\week9assignment.cpp(285) : error C2143: syntax error : missing ';' before '{'
1>c:\wxwidgets-2.8.8\week9assignment\week9assignment\week9assignment.cpp(285) : error C2447: '{' : missing function header (old-style formal list?)
1>c:\wxwidgets-2.8.8\week9assignment\week9assignment\week9assignment.cpp(289) : error C2065: 'string' : undeclared identifier
1>c:\wxwidgets-2.8.8\week9assignment\week9assignment\week9assignment.cpp(289) : error C2146: syntax error : missing ')' before identifier 'n'
1>c:\wxwidgets-2.8.8\week9assignment\week9assignment\week9assignment.cpp(289) : error C2761: 'void Player::set_name(void)' : member function redeclaration not allowed
1>c:\wxwidgets-2.8.8\week9assignment\week9assignment\week9assignment.cpp(289) : error C2059: syntax error : ')'
1>c:\wxwidgets-2.8.8\week9assignment\week9assignment\week9assignment.cpp(290) : error C2143: syntax error : missing ';' before '{'
1>c:\wxwidgets-2.8.8\week9assignment\week9assignment\week9assignment.cpp(290) : error C2447: '{' : missing function header (old-style formal list?)
1>c:\wxwidgets-2.8.8\week9assignment\week9assignment\week9assignment.cpp(299) : error C2143: syntax error : missing ';' before 'Player::get_name'
1>c:\wxwidgets-2.8.8\week9assignment\week9assignment\week9assignment.cpp(299) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\wxwidgets-2.8.8\week9assignment\week9assignment\week9assignment.cpp(300) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\wxwidgets-2.8.8\week9assignment\week9assignment\week9assignment.cpp(301) : error C2065: 'name' : undeclared identifier
1>c:\wxwidgets-2.8.8\week9assignment\week9assignment\week9assignment.cpp(307) : error C2143: syntax error : missing ';' before 'if'
1>c:\wxwidgets-2.8.8\week9assignment\week9assignment\week9assignment.cpp(391) : error C2146: syntax error : missing ';' before identifier 'text'
1>c:\wxwidgets-2.8.8\week9assignment\week9assignment\week9assignment.cpp(391) : error C2065: 'text' : undeclared identifier
1>c:\wxwidgets-2.8.8\week9assignment\week9assignment\week9assignment.cpp(392) : error C2110: '+' : cannot add two pointers
1>c:\wxwidgets-2.8.8\week9assignment\week9assignment\week9assignment.cpp(394) : error C2065: 'text' : undeclared identifier
1>c:\wxwidgets-2.8.8\week9assignment\week9assignment\week9assignment.cpp(394) : error C2228: left of '.c_str' must have class/struct/union
1>        type is ''unknown-type''
1>c:\wxwidgets-2.8.8\week9assignment\week9assignment\week9assignment.cpp(402) : error C2146: syntax error : missing ';' before identifier 'text'
1>c:\wxwidgets-2.8.8\week9assignment\week9assignment\week9assignment.cpp(402) : error C2065: 'text' : undeclared identifier
1>c:\wxwidgets-2.8.8\week9assignment\week9assignment\week9assignment.cpp(403) : error C2110: '+' : cannot add two pointers
1>c:\wxwidgets-2.8.8\week9assignment\week9assignment\week9assignment.cpp(405) : error C2065: 'text' : undeclared identifier
1>c:\wxwidgets-2.8.8\week9assignment\week9assignment\week9assignment.cpp(405) : error C2228: left of '.c_str' must have class/struct/union
1>        type is ''unknown-type''
1>c:\wxwidgets-2.8.8\week9assignment\week9assignment\week9assignment.cpp(429) : error C2660: 'Player::set_name' : function does not take 1 arguments
1>Build log was saved at "file://c:\wxWidgets-2.8.8\Week9Assignment\Week9Assignment\Debug\BuildLog.htm"
1>Week9Assignment - 41 error(s), 2 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
The following is the code to my program:

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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
#include <wx/wx.h>
#include <string>
#include <cstdlib>

const double PI = 3.141592653589793;

const int ID_GUESS = 1000;
const int ID_PLAYER_NAME = 1001;
const int ID_PLAYER_LEVEL = 1002;

/**
	A clock that can draw its face.
*/
class Clock
{
public:
	/**
		Constructs a clock with a given center and radius.
		@param x the x-coordinate of the center
		@param y the y-coordinate of the center
		@param r the radius of the clock
	*/
	Clock(int x, int y, int r);

	/**
		Sets the current time.
		@param h the hours to set
		@param m the minutes to set
	*/
	void set_time(int h, int m);

	/**
		Draws the clock face, with tick marks and hands.
		@param dc the device context to draw on
	*/
	void draw(wxDC& dc) const;
private:
	/**
		Draws a tick mark (hour or minute mark).
		@param dc the device context to draw on
		@param angle the angle in minutes (0. . .59, 0 = top)
		@param length the length of the tick mark, as a fraction
		of the radius (between 0.0 and 1.0)
	*/
	void draw_tick(wxDC& dc, double angle, double length) const;

	/**
		Draws a hand, starting from the center.
		@param dc the device context to draw on
		@param angle the angle in minutes (0. . .59, 0 = top)
		@param length the length of the hand, as a fraction
		of the radius (between 0.0 and 1.0)
	*/
	void draw_hand(wxDC& dc, double angle, double length) const;

	int hours;
	int minutes;
	int centerx;
	int centery;
	int radius;
};

/**
	The player of the clock game.
*/
class Player
{
public:
	/**
		Constructs a player with name "Player",
		level 1, and score 0.
	*/
	Player();

	/**
		Increments the score.  Moves to next level if current
		level complete.
	*/
	void increment_score();

	/**
		Gets the current level.
		@return the level
	*/
	int get_level() const;

	/**
		Gets the player's name.
		@return the name
	*/
	string get_name() const;

	/**
		Sets the player's level.
		@param 1 the level
	*/
	void set_level(int 1);

	/**
		Sets the player's name.
		@param n the name
	*/
	void set_name(string n);
private:
	string name;
	int score;
	int level;
};

/**
	The window that shows the clock.
*/
class ClockWindow : public wxWindow
{
public:
	/**
		Constructs a clock window.
		@param parent the parent window
	*/
	ClockWindow(wxWindow* parent);
	/**
		Sets the time of the clock and repaints it.
		@param h the hours
		@param m the minutes
	*/
	void set_time(int h, int m);
	/**
		Paints the clock.
		@param event the event descriptor
	*/
	void OnPaint(wxPaintEvent& event);
private:
	Clock clock;
	DECLARE_EVENT_TABLE()
};

/**
	The frame that contains the clock window and the 
	fields for entering a guess.
*/
class GameFrame : public wxFrame
{
public:
	/**
		Constructs the game frame.
	*/
	GameFrame();

	/**
		Starts a new round, with a new clock time.
	*/
	void new_round();

	/**
		Processes the player's guess.
		@param event the event descriptor
	*/
	void OnGuess(wxCommandEvent& event);

	/**
		Prompts the player to enter a name.
		@param event the event descriptor
	*/
	void OnPlayerName(wxCommandEvent& event);

	/**
		Prompts the player to enter a level.
		@param event the event descriptor
	*/
	void OnPlayerLevel(wxCommandEvent& event);
private:
	ClockWindow* window;
	wxTextCtrl* hour_text;
	wxTextCtrl* minute_text;
	Player player;

	int current_hours;
	int current_minutes;
	int tries;
	DECLARE_EVENT_TABLE()
};

/**
	The clock game application.
*/
class GameApp : public wxApp
{
public:
	/**
		Constructs the application.
	*/
	GameApp();
	virtual bool OnInit();
private:
	GameFrame* frame;
};

DECLARE_APP(GameApp)

IMPLEMENT_APP(GameApp)

BEGIN_EVENT_TABLE(ClockWindow, wxWindow)
	EVT_PAINT(ClockWindow::OnPaint)
END_EVENT_TABLE()

BEGIN_EVENT_TABLE(GameFrame, wxFrame)
	EVT_BUTTON(ID_GUESS, GameFrame::OnGuess)
	EVT_MENU(ID_PLAYER_NAME, GameFrame::OnPlayerName)
	EVT_MENU(ID_PLAYER_LEVEL, GameFrame::OnPlayerLevel)
END_EVENT_TABLE()

/**
	Sets the seed of the random number generator.
*/
void rand_seed()
{
	int seed = static_cast<int>(time(0));
	srand(seed);
}

/**
	Returns a random integer in a range.
	@param a the bottom of the range
	@param b the top of the range
	@return a random number x, a <= x and x <= b
*/
int rand_int(int a, int b)
{
	return a + rand() % (b - a + 1);
}

Clock::Clock(int x, int y, int r)
{
	centerx = x;
	centery = y;
	radius = r;
}

void Clock::set_time(int h, int m)
{
	hours = h;
	minutes = m;
}

void Clock::draw_tick(wxDC& dc, double angle,
	double length) const
{
	double alpha -PI / 2 + 6 * angle * PI / 180;
	dc.DrawLine(
		centerx + static_cast<int>(
			cos(alpha) * radius * (1 - length)),
		centery + static_cast<int>(
			sin(alpha) * radius * (1 - length)),
		centerx + static_cast<int>(cos(alpha) * radius),
		centery + static_cast<int>(sin(alpha) * radius));
}

void Clock::draw(wxDC& dc) const
{
	dc.DrawEllipse(centerx - radius, centery - radius,
		2 * radius, 2 * radius);
	const double HOUR_TICK_LENGTH = 0.2;
	const double MINUTE_TICK_LENGTH = 0.1;
	const double HOUR_HAND_LENGTH = 0.6;
	const double MINUTE_HAND_LENGTH = 0.75;
	for (int i = 0; i < 12; i++)
	{
		draw_tick(dc, minutes, HOUR_TICK_LENGTH);
		int j;
		for (j = 1; j <= 4; j++)
			draw_tick(dc, i * 5 + j, MINUTE_TICK_LENGTH);
	}
	draw_hand(dc, minutes, MINUTE_HAND_LENGTH);
	draw_hand(dc, (hours + minutes / 60.0) * 5, HOUR_HAND_LENGTH);
}

Player::Player()
{
	name = "Player";
	level = 1;
	score = 0;
}

void Player::set_level(int 1)
{
	level = 1;
}

void Player::set_name(string n)
{
	name = n;
}

int Player::get_level() const
{
	return level;
}

string Player::get_name() const
{
	return name;
}

void Player::increment_score()
{
	score++
	if (score % 5 == 0 && level < 4)
		level++;
}

Here is the rest of the 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
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
ClockWindow::ClockWindow(wxWindow* parent)
	: wxWindow(parent, -1),
	clock(200, 200, 200)
{
}

void ClockWindow::OnPaint(wxPaintEvent &event)
{
	wxPaintDC dc(this);
	dc.SetBrush(*wxTRANSPARENT_BRUSH);
	clock.draw(dc);
}

void ClockWindow::set_time(int h, int m)
{
	clock.set_time(h, m);
	Refresh();
}

GameFrame::GameFrame()
	: wxFrame(NULL, -1, "GameFrame")
{
	// initialize menu
	wxMenu* menu = new wxMenu();
	menu->Append(ID_PLAYER_NAME, "Name");
	menu->Append(ID_PLAYER_LEVEL, "Level");

	// adds menu to menu bar
	wxMenuBar* menu_bar = new wxMenuBar();
	SetMenuBar(menu_bar);
	menu_bar->Append(menu, "Player");

	window = new ClockWindow(this);

	hour_text = new wxTextCtrl(this, -1);
	minute_text = new wxTextCtrl(this, -1);

	wxButton* guess_button = new wxButton(this,
		ID_GUESS, "Guess");

	wxBoxSizer* bottom_sizer = new wxBoxSizer(wxHORIZONTAL);
	bottom_sizer->Add(new wxStaticText(this, -1, "Hours"));
	bottom_sizer->Add(hour_text);
	bottom_sizer->Add(new wxStaticText(this, -1, "Minutes"));
	bottom_sizer->Add(minute_text);
	bottom_sizer->Add(guess_button);

	wxBoxSizer* frame_sizer = new wxBoxSizer(wxVERTICAL);
	frame_sizer->Add(window, 1, wxGROW);
	frame_sizer->Add(bottom_sizer, 0, wxALIGN_CENTER);

	SetAutoLayout(true);
	SetSizer(frame_sizer);

	new_round();
}

void GameFrame::OnGuess(wxCommandEvent &event)
{
	tries++;
	int hours = atoi(hour_text->GetValue().c_str());
	int minutes = atoi(minute_text->GetValue().c_str());
	if (hours < 1 || hours > 12)
	{
		wxMessageDialog* dialog = new wxMessageDialog(this,
			"Hours must be between 1 and 12");
		dialog->ShowModal();
		dialog->Destroy();
		return;
	}
	if (minutes < 0 || minutes > 59)
	{
		wxMessageDialog* dialog = new wxMessageDialog(this,
			"Hours must be between 1 and 12");
		dialog->ShowModal();
		dialog->Destroy();
		return;
	}
	if (current_hours == hours && current_minutes == minutes)
	{
		string text = "Congratulations, " + player.get_name()
			+ "! That is correct.";
		wxMessageDialog* dialog = new wxMessageDialog(this,
			text.c_str());
		dialog->ShowModal();
		dialog->Destroy();
		player.increment_score();
		new_round();
	}
	else
	{
		string text = "Sorry, " + player.get_name()
			+ "!  That is not correct.";
		wxMessageDialog* dialog = new wxMessageDialog(this,
			text.c_str());
		dialog->ShowModal();
		dialog->Destroy();
		if (tries == 2) new_round();
	}
}

void GameFrame::new_round()
{
	tries = 0;
	int level = player.get_level();
	if(level == 1) current_minutes = 0;
	else if (level == 2) current_minutes = 15 * rand_int(0, 3);
	else if (level == 3) current_minutes = 5 * rand_int(0, 11);
	else current_minutes = rand_int(0, 59);
	current_hours = rand_int(1, 12);
	window->set_time(current_hours, current_minutes);
}

void GameFrame::OnPlayerName(wxCommandEvent& event)
{
	wxTextEntryDialog* dialog = new wxTextEntryDialog(this,
		"What is your name?");
	dialog->ShowModal();
	player.set_name(dialog->GetValue().c_str());
	dialog->Destroy();
}

void GameFrame::OnPlayerLevel(wxCommandEvent& event)
{
	wxTextEntryDialog* dialog = new wxTextEntryDialog(this,
		"At what level do you want to play? (1-4)");
	dialog->ShowModal();
	int level = atoi(dialog->GetValue().c_str());
	dialog->Destroy();
	if (level < 1 || level > 4)
	{
		wxMessageDialog* dialog = new wxMessageDialog(this,
			"The level must be between 1 and 4");
		dialog->ShowModal();
		dialog->Destroy();
		return;
	}
	player.set_level(level);
}

GameApp::GameApp()
{
	rand_seed();
	frame = new GameFrame();
}

bool GameApp::OnInit()
{
	frame->Show(true);
	return true;
}
Topic archived. No new replies allowed.