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

Need help on C Programming

OpenStudy (calculusxy):

Imagine a turtle crawling around aimlessly so that it turns to the left or to the right (by 90 degrees) and then walks forward 25 units exactly 100 times. Create a flowchart or write pseudocode for accomplishing this dizzying task.

OpenStudy (calculusxy):

@jango_IN_DTOWN

OpenStudy (jango_in_dtown):

Have you worked this one out?

OpenStudy (calculusxy):

I have to use these for choosing the random movement of going left or right: #include <stdio.h> #include <stdlib.h> #include <time.h> int main(void) { srand(time(NULL)); /* Seed the random number generator */ `int answer = rand() % 100 + 1; /* Randomly select a number */` this can be changed

OpenStudy (calculusxy):

Nope. I am confused on how I can make the computer choose randomly whether to go left/right.

OpenStudy (jango_in_dtown):

you dont have to create a program, it said to create flowchart or pseudocode

OpenStudy (calculusxy):

But I was thinking of assigning left a number and right another number. For example left = 0 and right = 1. Then I can perhaps use: int answer = rand() % 100 + 1; / to order to randomly select a number

OpenStudy (calculusxy):

Well in another part it says for me to implement the flowchart or pseudocode by writing it out as a C program

OpenStudy (jango_in_dtown):

It will be better if you post this question in computer science portion, I will be studying string functions in a later course. Right now I am not acquainted with it properly. I know those portions of C in which numerical methods are involved in mathematics

OpenStudy (calculusxy):

I am honestly not so sure about string functions myself. My teacher just said to use that whenever we're asking the computer to choose something random.

OpenStudy (calculusxy):

For example, let's say we have `int n` Can I say `int n = rand() % 2;` I learned that when choosing the random numbers n will subtract 1. Therefore, by choosing 2 and subtracting 1 I will get the number 1. And I designated that left = 0 and right = 1

OpenStudy (jango_in_dtown):

ok, so when you declare int n, it will takes integer values only and since you operate modulus by 2, it will have answers 0 or 1, nothing else. This part is correct

OpenStudy (calculusxy):

OK

OpenStudy (calculusxy):

So can we start creating the program?

OpenStudy (jango_in_dtown):

But how do you show the turtle moves 25 units 100 times, I am not familiar with this stuff

OpenStudy (calculusxy):

I guess with while loop?

OpenStudy (calculusxy):

we can use this perhaps? while (time=100) { turtle_forward(25); }

OpenStudy (jango_in_dtown):

Your program worked?

OpenStudy (calculusxy):

I am still writing it. It's almost done

OpenStudy (jango_in_dtown):

Good

OpenStudy (calculusxy):

How do I move a file from one directory to the other?

OpenStudy (calculusxy):

I accidentally wrote my program one directory "experiments" but it's supposed to be in another one named "turtle"

OpenStudy (jango_in_dtown):

GO in the directory you wrote, find the file name. It will have the extension .CPP. Just copy and paste it

OpenStudy (jango_in_dtown):

in the required directory

OpenStudy (calculusxy):

OK did it !

OpenStudy (jango_in_dtown):

paste the program code here..

OpenStudy (calculusxy):

I accidentally deleted while compiling it!

OpenStudy (jango_in_dtown):

you type ctrl and v at once

OpenStudy (jango_in_dtown):

it will be back

OpenStudy (calculusxy):

It's not working

OpenStudy (jango_in_dtown):

undo option not working?

OpenStudy (calculusxy):

Nope!

OpenStudy (jango_in_dtown):

then you have to work it out again...

OpenStudy (calculusxy):

Yeah I guess so. Just give me like 5 minutes plz

OpenStudy (jango_in_dtown):

ok sure.:)

OpenStudy (calculusxy):

#include <stdio.h> #include <stdlib.h> #include <time.h> #include "turtle.h" int main(void) { int times; srand(time(NULL)); while (times<=100) { int left_or_right = rand() % 2; if (left_or_right==1) { turtle_turn_left(90); } else { turtle_turn_right(90); } turtle_forward(200); times++; } turtle_save_bmp("drawing.bmp"); turtle_cleanup(); return 0; }

OpenStudy (calculusxy):

When I try to run it Preview says that the file cannot be opened

OpenStudy (jango_in_dtown):

#include<turtle.h>

OpenStudy (calculusxy):

they say it needs to be #include "turtle.h"

OpenStudy (jango_in_dtown):

wait a bit, I dont know about drawing.. Which book are you reading?

OpenStudy (calculusxy):

What do you mean by what book I am reading?

OpenStudy (jango_in_dtown):

I mean, reference book, which you follow to learn C++

OpenStudy (calculusxy):

It's an elective class I am taking at my school

OpenStudy (jango_in_dtown):

So you dont read from any other refenrence book? /i am not acquainted with drawing in C++

OpenStudy (calculusxy):

This is supposed to be only C

OpenStudy (jango_in_dtown):

Yeah, C or C++ you may use same software package, only a few commands are different

OpenStudy (calculusxy):

OK thank you for helping though :)

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!