@phi Can you help me with C Programming?
Make a flowchart for a program that draws a square with side length 200 pixels. Your program must use a while loop. Afterward, implement your algorithm in a C program.
how far did you get ?
turtle_init(600,600); int angle=0; while(angle<=90); { turtle_forward(200); turtle_left(90); angle ++; }
I am not so sure about my while loop part.
#include "turtle.h" int main(void) { turtle_init(600,600); int angle=0; while(angle<=90) { turtle_forward(200); turtle_turn_left(90); angle ++; } turtle_save_bmp("square.bmp"); turtle_cleanup(); return 0; }
ok, so your idea is to start at 600,600 and move forward 200 (does that draw a line or does that just move ? we want to draw a line) also, what direction are we facing? do we have to say ?
I complied using clang and ran it with `open square.bmp` and got this:
ok, but you should test while (angle < 4) instead of while(angle<=90) what do you get ?
i am checking it out now
it shows the same drawing. why is angle < 4 better than angle<=90?
"angle" is not a good name for the variable. "side" would make more sense. each time you "go through the loop" you draw one line (side) the last statement in the loop angle ++ changes angle from 0 to 1 (the first time) and then 2 and then 3 after that, you keep drawing until you have done 91 sides (i.e. with angle <= 90 you are going around the square 91 times)
oh that makes sense. sorry i got mixed up with my variable
if you wanted to count "angle" then you want to only go 360 degrees and instead of angle ++ you would write angle += 90 (add 90 degrees each time you turn) and then do while (angle < 360)
Can you help me with another question @phi ?
Join our real-time social learning platform and learn together with your friends!