LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-07-2005, 04:05 PM   #1
mshinska
LQ Newbie
 
Registered: Oct 2005
Posts: 14

Rep: Reputation: 0
syntax error in C ++


for the following section of code I keep getting these two errors:

syntax error before '}' token

and

confused by earlier errors bailing out

the small section of code is:
do
{
angle = 2*PI*rand()/RAND_MAX;
dx = cos(angle);
dy = sin(angle);
}


The whole code(that i have done):

#include <iostream>

#include <cstdlib>

#include <cmath>

using namespace std;

int main(void)

{
int atHome=0, stepsToTry=5000, home, start;
double x, y, dx, dy, angle;
const int minx = -10;
const int maxx = 10;
const int miny = -10;
const int maxy = 10;
const double PI = 4*atan(1.0);

cout << "Will Waldo make it home? \n\n";

cout << "Input an int to start the random number generator: ";
int myStart;
cin >> myStart;
srand(myStart);

home = (((x>=8) && (x<=10)) && ((y>=8) && (y<=10)));
start = ((x = 0) && (y = 0));

for (stepsToTry = 5000; stepsToTry>0; stepsToTry = stepsToTry - 1)
{
do
{
angle = 2*PI*rand()/RAND_MAX;
dx = cos(angle);
dy = sin(angle);
}
}

return 0;

}

any help at all welcome
 
Old 10-07-2005, 04:41 PM   #2
vladmihaisima
Member
 
Registered: Oct 2002
Location: Delft, Netherlands
Distribution: Gentoo
Posts: 196

Rep: Reputation: 33
What is the 'do' supposed to do ?

In C/C++ there exists only a construct : "do { statments; } while(condition);" , not just do.
 
Old 10-07-2005, 04:48 PM   #3
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
It would be enormously helpful if you could:

1. Cut and paste the exact error message

2. Use the [code] tags around your sample code

3. Post back an "ack" to the group when you've solved a problem

Thanx in advance .. PSM

PS:
vladmihaisima is undoubtedly right about the "do" without any "while()" being
the source of your error.

But the exact error - and better formatting - would have helped.

And by all means, please let us know how/if you resolved the problem.

Among other things, that makes *your* question more valuable to *other* LQ folks who might have the *same* question!
 
Old 10-07-2005, 04:53 PM   #4
mshinska
LQ Newbie
 
Registered: Oct 2005
Posts: 14

Original Poster
Rep: Reputation: 0
I have added a while and fixed that error. I tried to work in to small of increaments. Thanks!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
c++ syntax error...HELP!! lmvent Programming 3 09-30-2005 02:40 PM
Many errors when 'make'ing (example: error: syntax error before `::' token) darkblade Linux - Software 5 03-02-2005 03:00 PM
C++ syntax error before :: token HELP, i cant find the syntax error :( qwijibow Programming 2 12-14-2004 06:09 PM
Where's the syntax error tamtam Programming 2 07-24-2004 09:07 AM
ERROR running make when installing Nvidia drivers (syntax error) randyriver10 Linux - Software 5 02-21-2004 04:51 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:25 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration