error C2059: syntax error : 'namespace'

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Sep 2007
Posts: 11
Reputation: jarv is an unknown quantity at this point 
Solved Threads: 0
jarv jarv is offline Offline
Newbie Poster

Re: error C2059: syntax error : 'namespace'

 
0
  #11
Sep 13th, 2007
can someone please help?!

I am very new to this!
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,630
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 718
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: error C2059: syntax error : 'namespace'

 
0
  #12
Sep 13th, 2007
>can someone please help?!
Two very qualified people have already given you good advice. Are you ignoring their suggestions and hoping that someone does all of the work for you? If not, explain what you've done to troubleshoot and how it didn't work.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 11
Reputation: jarv is an unknown quantity at this point 
Solved Threads: 0
jarv jarv is offline Offline
Newbie Poster

Re: error C2059: syntax error : 'namespace'

 
0
  #13
Sep 13th, 2007
it says:

1>c:\users\john\documents\visual studio 2005\projects\speedgame\speedgame\Form1.h(23) : error C2143: syntax error : missing ',' before '}'

so i think it's line 23 where it goes }{
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 11
Reputation: jarv is an unknown quantity at this point 
Solved Threads: 0
jarv jarv is offline Offline
Newbie Poster

Re: error C2059: syntax error : 'namespace'

 
0
  #14
Sep 13th, 2007
Originally Posted by Narue View Post
>can someone please help?!
Two very qualified people have already given you good advice. Are you ignoring their suggestions and hoping that someone does all of the work for you? If not, explain what you've done to troubleshoot and how it didn't work.

I have gone through the { and the } and looked for where to put a ;

i wrote this code from a book and i am double checking it!
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,398
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1466
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: error C2059: syntax error : 'namespace'

 
0
  #15
Sep 13th, 2007
forget about the semicolon for now, just concentrate on finding the mismatches braces. Books sometimes contain errors due to poor or inadequate proofreading -- or more likely you copied it wrong.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: error C2059: syntax error : 'namespace'

 
0
  #16
Sep 13th, 2007
Like I said, the problem was how you approached the problem from the beginning.

This is your post.
"It's the 4th down and 50 yards to go, with 20 seconds remaining on the clock, and you need 7 points for the win".
In essence, a "hail mary" pass into the end zone in the hopes that you'll strike lucky.

IMO, you need to create a new project and build up slowly this time, copy/pasting small sections of this project to it, along with lots of compile and test as you go.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,398
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1466
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: error C2059: syntax error : 'namespace'

 
0
  #17
Sep 13th, 2007
Originally Posted by Salem View Post
IMO, you need to create a new project and build up slowly this time, copy/pasting small sections of this project to it, along with lots of compile and test as you go.
Yup, I suggested that too, but I suppose some people don't take suggestions like that.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,630
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 718
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: error C2059: syntax error : 'namespace'

 
0
  #18
Sep 13th, 2007
You had quite a few transcription errors. In other words, unless the book is absolutely horrid, you introduced syntax errors on your own when typing the code in. I've cleaned it up for you and fixed the syntax errors. Don't expect me to do it again:
  1. #pragma once
  2.  
  3. namespace speedgame {
  4. using namespace System;
  5. using namespace System::ComponentModel;
  6. using namespace System::Collections;
  7. using namespace System::Windows::Forms;
  8. using namespace System::Data;
  9. using namespace System::Drawing;
  10.  
  11. /// <summary>
  12. /// Summary for Form1
  13. ///
  14. /// WARNING: If you change the name of this class, you will need to change the
  15. /// 'Resource File Name' property for the managed resource compiler tool
  16. /// associated with all .resx files this class depends on. Otherwise,
  17. /// the designers will not be able to interact properly with localized
  18. /// resources associated with this form.
  19. /// </summary>
  20. public ref class Form1: public System::Windows::Forms::Form {
  21. public:
  22. Form1()
  23. {
  24. InitializeComponent();
  25. }
  26.  
  27. protected:
  28. /// <summary>
  29. /// Clean up any resources being used.
  30. /// </summary>
  31. ~Form1()
  32. {
  33. if ( components )
  34. delete components;
  35. }
  36.  
  37. private:
  38. System::Windows::Forms::ToolTip^ tipControl;
  39. System::Windows::Forms::Timer^ tmrControl;
  40. System::Windows::Forms::TextBox^ txtDisplay;
  41. System::Windows::Forms::TextBox^ txtEntry;
  42. System::Windows::Forms::Label^ lblInstructions;
  43. System::Windows::Forms::Label^ lblSourceText;
  44. System::Windows::Forms::Label^ lblEntryText;
  45. System::Windows::Forms::StatusStrip^ stsControl;
  46. System::Windows::Forms::ToolStripStatusLabel^ stsLabel;
  47. System::Windows::Forms::Button^ btnGo;
  48. System::Windows::Forms::Button^ btnDone;
  49. System::Windows::Forms::Button^ btnExit;
  50.  
  51. System::ComponentModel::IContainer^ components;
  52.  
  53. Int16 intWrong; //Tracks number of strikes
  54. Int16 intCount; //Tracks number of tries
  55. Int16 intTimer; //Tracks elapsed time
  56.  
  57. #pragma region Windows Form Designer generated code
  58. /// <summary>
  59. /// Required method for Designer support - do not modify
  60. /// the contents of this method with the code editor.
  61. /// </summary>
  62. void InitializeComponent(void)
  63. {
  64. this->components = (gcnew System::ComponentModel::Container());
  65. this->tipControl = (gcnew System::Windows::Forms::ToolTip(this->components));
  66. this->txtDisplay = (gcnew System::Windows::Forms::TextBox());
  67. this->txtEntry = (gcnew System::Windows::Forms::TextBox());
  68. this->btnGo = (gcnew System::Windows::Forms::Button());
  69. this->btnDone = (gcnew System::Windows::Forms::Button());
  70. this->btnExit = (gcnew System::Windows::Forms::Button());
  71. this->tmrControl = (gcnew System::Windows::Forms::Timer(this->components));
  72. this->lblInstructions = (gcnew System::Windows::Forms::Label());
  73. this->lblSourceText = (gcnew System::Windows::Forms::Label());
  74. this->lblEntryText = (gcnew System::Windows::Forms::Label());
  75. this->stsControl = (gcnew System::Windows::Forms::StatusStrip());
  76. this->stsLabel = (gcnew System::Windows::Forms::ToolStripStatusLabel());
  77. this->stsControl->SuspendLayout();
  78. this->SuspendLayout();
  79. //
  80. // txtDisplay
  81. //
  82. this->txtDisplay->Location = System::Drawing::Point(40, 55);
  83. this->txtDisplay->Name = L"txtDisplay";
  84. this->txtDisplay->ReadOnly = true;
  85. this->txtDisplay->Size = System::Drawing::Size(675, 20);
  86. this->txtDisplay->TabIndex = 0;
  87. this->tipControl->SetToolTip(this->txtDisplay, L"Displays source text string");
  88. //
  89. // txtEntry
  90. //
  91. this->txtEntry->Location = System::Drawing::Point(40, 121);
  92. this->txtEntry->Name = L"txtEntry";
  93. this->txtEntry->ReadOnly = true;
  94. this->txtEntry->Size = System::Drawing::Size(675, 20);
  95. this->txtEntry->TabIndex = 1;
  96. this->tipControl->SetToolTip(this->txtEntry, L"Type your text here");
  97. //
  98. // btnGo
  99. //
  100. this->btnGo->Location = System::Drawing::Point(43, 216);
  101. this->btnGo->Name = L"btnGo";
  102. this->btnGo->Size = System::Drawing::Size(75, 23);
  103. this->btnGo->TabIndex = 6;
  104. this->btnGo->Text = L"GO";
  105. this->tipControl->SetToolTip(this->btnGo, L"Display new text string");
  106. this->btnGo->UseVisualStyleBackColor = true;
  107. this->btnGo->Click += gcnew System::EventHandler(this, &Form1::btnGo_Click);
  108. //
  109. // btnDone
  110. //
  111. this->btnDone->Enabled = false;
  112. this->btnDone->Location = System::Drawing::Point(639, 216);
  113. this->btnDone->Name = L"btnDone";
  114. this->btnDone->Size = System::Drawing::Size(75, 23);
  115. this->btnDone->TabIndex = 7;
  116. this->btnDone->Text = L"Done";
  117. this->tipControl->SetToolTip(this->btnDone, L"Check typing");
  118. this->btnDone->UseVisualStyleBackColor = true;
  119. this->btnDone->Click += gcnew System::EventHandler(this, &Form1::btnDone_Click);
  120. //
  121. // btnExit
  122. //
  123. this->btnExit->Location = System::Drawing::Point(639, 9);
  124. this->btnExit->Name = L"btnExit";
  125. this->btnExit->Size = System::Drawing::Size(75, 23);
  126. this->btnExit->TabIndex = 8;
  127. this->btnExit->Text = L"Exit";
  128. this->tipControl->SetToolTip(this->btnExit, L"Exit game");
  129. this->btnExit->UseVisualStyleBackColor = true;
  130. //
  131. // tmrControl
  132. //
  133. this->tmrControl->Interval = 1000;
  134. this->tmrControl->Tick += gcnew System::EventHandler(this, &Form1::tmrControl_Tick);
  135. //
  136. // lblInstructions
  137. //
  138. this->lblInstructions->AutoSize = true;
  139. this->lblInstructions->Location = System::Drawing::Point(12, 9);
  140. this->lblInstructions->Name = L"lblInstructions";
  141. this->lblInstructions->Size = System::Drawing::Size(511, 13);
  142. this->lblInstructions->TabIndex = 2;
  143. this->lblInstructions->Text = L"Click Go to begin. You have 15 seconds to type the text displayed in the source t"
  144. L"ext field exactly as shown.";
  145. //
  146. // lblSourceText
  147. //
  148. this->lblSourceText->AutoSize = true;
  149. this->lblSourceText->Location = System::Drawing::Point(40, 39);
  150. this->lblSourceText->Name = L"lblSourceText";
  151. this->lblSourceText->Size = System::Drawing::Size(68, 13);
  152. this->lblSourceText->TabIndex = 3;
  153. this->lblSourceText->Text = L"Source Text:";
  154. //
  155. // lblEntryText
  156. //
  157. this->lblEntryText->AutoSize = true;
  158. this->lblEntryText->Location = System::Drawing::Point(40, 105);
  159. this->lblEntryText->Name = L"lblEntryText";
  160. this->lblEntryText->Size = System::Drawing::Size(79, 13);
  161. this->lblEntryText->TabIndex = 4;
  162. this->lblEntryText->Text = L"Enter text here:";
  163. //
  164. // stsControl
  165. //
  166. this->stsControl->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(1) {this->stsLabel});
  167. this->stsControl->Location = System::Drawing::Point(0, 270);
  168. this->stsControl->Name = L"stsControl";
  169. this->stsControl->Size = System::Drawing::Size(773, 22);
  170. this->stsControl->TabIndex = 5;
  171. this->stsControl->Text = L"statusStrip1";
  172. //
  173. // stsLabel
  174. //
  175. this->stsLabel->Name = L"stsLabel";
  176. this->stsLabel->Size = System::Drawing::Size(118, 17);
  177. this->stsLabel->Text = L"toolStripStatusLabel1";
  178. //
  179. // Form1
  180. //
  181. this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
  182. this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
  183. this->ClientSize = System::Drawing::Size(773, 292);
  184. this->Controls->Add(this->btnExit);
  185. this->Controls->Add(this->btnDone);
  186. this->Controls->Add(this->btnGo);
  187. this->Controls->Add(this->stsControl);
  188. this->Controls->Add(this->lblEntryText);
  189. this->Controls->Add(this->lblSourceText);
  190. this->Controls->Add(this->lblInstructions);
  191. this->Controls->Add(this->txtEntry);
  192. this->Controls->Add(this->txtDisplay);
  193. this->FormBorderStyle = System::Windows::Forms::FormBorderStyle::FixedSingle;
  194. this->Name = L"Form1";
  195. this->StartPosition = System::Windows::Forms::FormStartPosition::CenterScreen;
  196. this->Text = L"The Speed Game";
  197. this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
  198. this->stsControl->ResumeLayout(false);
  199. this->stsControl->PerformLayout();
  200. this->ResumeLayout(false);
  201. this->PerformLayout();
  202.  
  203. }
  204. #pragma endregion
  205.  
  206. System::Void Form1_Load ( System::Object^ sender, System::EventArgs^ e )
  207. {
  208. //set begginning data values
  209. intWrong = 0;
  210. intCount = 0;
  211. intTimer = 0;
  212. }
  213.  
  214. System::Void btnGo_Click ( System::Object^ sender, System::EventArgs^ e )
  215. {
  216. //Display game sentences according to level
  217. if( intCount == 0 )
  218. txtDisplay->Text = "Once upon a time there where three little pigs.";
  219. if( intCount == 1 )
  220. txtDisplay->Text = "In days gone by times where hard but the people were strong.";
  221. if( intCount == 2 )
  222. txtDisplay->Text = "Once in awhile something speacial happens even to the worst of people.";
  223. if( intCount == 3 )
  224. txtDisplay->Text = "When injustice rears its ugly hea, it is the duty of all good.";
  225. if( intCount == 4 )
  226. txtDisplay->Text = "It has been said that in the end there can only be one. Let that one be mighty Molly!";
  227.  
  228. btnDone->Enabled = true; //Activate done button
  229. btnGo->Enabled = false; //Disable Go button
  230.  
  231. //Allow text to be entered
  232. txtEntry->ReadOnly = false;
  233.  
  234. //Activate Timer
  235. tmrControl->Enabled = true;
  236. intTimer = 0;
  237. txtEntry->Focus();
  238. }
  239.  
  240. System::Void btnDone_Click ( System::Object^ sender, System::EventArgs^ e )
  241. {
  242. //Clear out status bar text
  243. stsControl->Text = "";
  244.  
  245. //Deactivate Timer so it doesn't keep going
  246. tmrControl->Enabled = false;
  247.  
  248. //Make sure player entered something
  249. if ( String::IsNullOrEmpty ( txtEntry->Text ) ) {
  250. //Show error
  251. MessageBox::Show ( "Error: You must enter something!" );
  252. //reset game
  253. txtDisplay->Text = "";
  254. btnDone->Enabled = false;
  255. btnGo->Enabled = true;
  256. txtEntry->ReadOnly = true;
  257. intTimer = 0;
  258. btnGo->Focus();
  259. return;
  260. }
  261.  
  262. if ( String::Compare ( txtEntry->Text, txtDisplay->Text ) == 0 ) {
  263. //handle Correct answer
  264. MessageBox::Show ( "Match! You typed the string in correctly!" );
  265. intCount += 1;
  266. intTimer = 0;
  267. }
  268. else {
  269. //handle incorrect answer
  270. MessageBox::Show ( String::Concat ( "Strike ",
  271. intWrong.ToString(), "! You made at least",
  272. " one typo." ) );
  273. intTimer = 0;
  274. }
  275.  
  276. //get set up for the next level
  277. txtEntry->Text = "";
  278. txtDisplay->Text = "";
  279. btnDone->Enabled = false;
  280. btnGo->Enabled = true;
  281. txtEntry->ReadOnly = true;
  282. intTimer = 0;
  283. btnGo->Focus();
  284.  
  285. //handle 3 strikes
  286. if ( intWrong == 3 ) {
  287. //inform play he/she is a begginer
  288. if ( intCount < 2 ) {
  289. MessageBox::Show ( "Game Over! Your "
  290. "typing skill level is Beginner. "
  291. "Please play again!" );
  292. intCount = 0;
  293. intWrong = 0;
  294. return;
  295. }
  296.  
  297. //inform play he/she is intermediate
  298. if ( intCount < 4 ) {
  299. MessageBox::Show ( "Game Over! Your "
  300. "typing skill level is intermediate. "
  301. "Please play again!" );
  302. intCount = 0;
  303. intWrong = 0;
  304. return;
  305. }
  306.  
  307. //inform play he/she is advanced
  308. if ( intCount < 5 ) {
  309. MessageBox::Show ( "Game Over! Your "
  310. "typing skill level is advanced. "
  311. "Please play again!" );
  312. intCount = 0;
  313. intWrong = 0;
  314. return;
  315. }
  316. }
  317. }
  318.  
  319. System::Void btnExit_Click ( System::Object^ sender, System::EventArgs^ e )
  320. {
  321. this->Close();
  322. }
  323.  
  324. System::Void tmrControl_Tick ( System::Object^ sender, System::EventArgs^ e )
  325. {
  326. //update timer value
  327. intTimer += 1;
  328. Int16 intTimeRemain = 15 - intTimer;
  329. stsLabel->Text = "Seconds remaining: ";
  330. stsLabel->Text = String::Concat( stsLabel, intTimeRemain.ToString() );
  331.  
  332. //handle running out of time
  333. if ( intTimer == 15 ) {
  334. intWrong += 1;
  335. tmrControl->Enabled = false;
  336. stsLabel->Text = "";
  337. MessageBox::Show ( String::Concat ( "Strike ",
  338. intWrong.ToString(), " - Time is up! Please",
  339. " try again." ) );
  340.  
  341. //reset game
  342. txtEntry->Text = "";
  343. txtDisplay->Text = "";
  344. btnDone->Enabled = false;
  345. btnGo->Enabled = true;
  346. txtEntry->ReadOnly = true;
  347. intTimer = 0;
  348. btnGo->Focus();
  349.  
  350. //handle 3 strikes
  351. if ( intWrong == 3 ) {
  352. //inform play he/she is a begginer
  353. if ( intCount < 2 ) {
  354. MessageBox::Show ( "Game Over! Your "
  355. "typing skill level is Beginner. "
  356. "Please play again!" );
  357. intCount = 0;
  358. intWrong = 0;
  359. return;
  360. }
  361.  
  362. //inform play he/she is intermediate
  363. if ( intCount < 4 ) {
  364. MessageBox::Show ( "Game Over! Your "
  365. "typing skill level is intermediate. "
  366. "Please play again!" );
  367. intCount = 0;
  368. intWrong = 0;
  369. return;
  370. }
  371.  
  372. //inform play he/she is advanced
  373. if( intCount < 5 ) {
  374. MessageBox::Show ( "Game Over! Your "
  375. "typing skill level is advanced. "
  376. "Please play again!" );
  377. intCount = 0;
  378. intWrong = 0;
  379. return;
  380. }
  381. }
  382.  
  383. //player is an expert!
  384. if ( intCount >= 5 ) {
  385. intCount = 0;
  386. intWrong = 0;
  387. MessageBox::Show ( "Game Complete! Your "
  388. "typing skill level is Expert! "
  389. "Please try again!" );
  390. }
  391. }
  392. }
  393. };
  394. }
Here are a few C++ tips:

1) Classes always end with a semicolon.
2) public, private, and protected are groupings. You don't have to specify an access modifier for every single member.
3) C++ is case sensitive. int16 is quite different from Int16.
4) Every opening { has to have a corresponding closing }.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 11
Reputation: jarv is an unknown quantity at this point 
Solved Threads: 0
jarv jarv is offline Offline
Newbie Poster

Re: error C2059: syntax error : 'namespace'

 
0
  #19
Sep 13th, 2007
thankyou so much!
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC