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 |
What is the 'do' supposed to do ?
In C/C++ there exists only a construct : "do { statments; } while(condition);" , not just do. |
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! |
I have added a while and fixed that error. I tried to work in to small of increaments. Thanks!
|
All times are GMT -5. The time now is 01:24 PM. |