Ask your own question, for FREE!
Mathematics 14 Online
OpenStudy (calculusxy):

@phi Can you help me with C Programming?

OpenStudy (calculusxy):

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.

OpenStudy (phi):

how far did you get ?

OpenStudy (calculusxy):

turtle_init(600,600); int angle=0; while(angle<=90); { turtle_forward(200); turtle_left(90); angle ++; }

OpenStudy (calculusxy):

I am not so sure about my while loop part.

OpenStudy (calculusxy):

#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; }

OpenStudy (phi):

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 ?

OpenStudy (calculusxy):

I complied using clang and ran it with `open square.bmp` and got this:

OpenStudy (phi):

ok, but you should test while (angle < 4) instead of while(angle<=90) what do you get ?

OpenStudy (calculusxy):

i am checking it out now

OpenStudy (calculusxy):

it shows the same drawing. why is angle < 4 better than angle<=90?

OpenStudy (phi):

"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)

OpenStudy (calculusxy):

oh that makes sense. sorry i got mixed up with my variable

OpenStudy (phi):

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)

OpenStudy (calculusxy):

Can you help me with another question @phi ?

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!