Turtle Graphics

My program is suppose to move the turtle until it reaches 30,000 steps. I'm confused as to how to use while loop. I know it's wrong, I'm just lost on the steps, basically how to set up the while loop.

#include <iostream>
#include <PCTurtle.h>
using namespace std;

int disTraveled;
int stepSize;
int i;


int main(void){
InitGraphics("Center");

Home();
int stepSize = 1;

while (disTraveled = 0){

}
(int i = 0; 1 <= 30000; i++)

{
stepSize = 1;
PenForward(1);
disTraveled = 1;
Pause(0.01);
TurnLeft(90);
stepSize = 2;
PenForward(2);
disTraveled = 2;
Pause(0.01);
stepSize = 3;
TurnLeft(90);
PenForward(3);
disTraveled = 3;
stepSize = 4;
Pause(0.01);
TurnLeft(90);
PenForward(4);
disTraveled = 4;
stepSize = 5;
Pause(0.01);
TurnLeft(90);
PenForward(5);
disTraveled = 5;

return 0;
}

So, for each iteration of the loop, the turtle is supposed to move forward 'i' number of steps, pause, and then rotate to the left by 90 degrees. Am I understanding this correctly?
1
2
3
4
5
6
7
8
9
10
11
12
	const int max_distance = 30000;
	int distance_travelled = 0;
	int iteration = 0;
	while (distance_travelled < max_distance) {
		
		iteration++;
		PenForward(iteration);
		distance_travelled += iteration;
		Pause(0.01);
		TurnLeft(90);

	}
Last edited on
while (disTraveled = 0)
The code inside the while loop will never execute.

Where is the code to draw the turtle on the screen?
Topic archived. No new replies allowed.