obsolete binding??
Here is my code:
#include <iostream> #include <cstdlib> #include <cmath> using namespace std; int main(void) { int atHome = 0; int stepsToTry = 5000; double x = 0; double y = 0; double dx = 0; double dy = 0; double angle; 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); for (int i = 0; i < stepsToTry; i = i + 1) { rand(); do { double angle = 2*PI*rand()/RAND_MAX; dx = cos(angle); dy = sin(angle); }while (atHome = 0); do { y = y + dy; }while (y >= -10 && y <= 10); do { x = x + dx; }while (x >= -10 && x <= 10); if (x>=8 && x<=10) { if(y >= 8 && y <= 10) { atHome = 1; } } } if (atHome) { cout << "Waldo made it home after taking " << i << "steps!\n"; } else { cout << "Waldo is still lost after taking" << stepsToTry << "steps\n\n"; cout << "Please play again and try to get Waldo home!\n"; } return 0; } Here is my error: waldo.cpp: In function 'int main()': waldo.cpp:41: name lookup of 'i' changed for new ISO 'for' scoping waldo.cpp:21: using obsolete binding at 'i' What the hell does that mean? |
When posting code, please, please, please use code tags around it. If you don't know what the code tags are, there is a button labeled "Code" above the message reply/new thread text box. Click it and it will insert the tags for you.
Your problem lies with scoping. The only place your code declares the variable is inside a for-loop: Code:
for (int i = 0; i < stepsToTry; i = i + 1) Code:
cout << "Waldo made it home after taking " << i << "steps!\n"; Either declare the variable outside the for loop, or reference a different variable in the cout statement to avoid the message. Also, you have a mistake in one of your do-while loops: Code:
do |
obsolete binding??
I was just faced with this weird anomaly also. Turns out I was accidentally adding the semicolon to the end of my for loop statement.
e.g. Code:
I'm sure this would effect all types of loops, including (but not limited too) While loops, Do loops, and maybe even if-else statement. Hope this helps. |
All times are GMT -5. The time now is 09:18 PM. |