468,513 Members | 1,763 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,513 developers. It's quick & easy.

could use help on a simple problem

I am taking a beginners class in programming and I am very lost. I need
to design a program that models the worm's behavior in the following
scenario: A worm is moving toward an apple. Each time it moves the worm
cuts the distance between itself and the apple by its own body length
until the worm is close enough to enter the apple. The worm can enter
the apple when it is within a body length of the apple. I now I need to
use an iteration control structure but have no idea where to start or
what to do in this one. Can some one help?

Aug 16 '06 #1
2 5530
"porky008" writes:
>I am taking a beginners class in programming and I am very lost. I need
to design a program that models the worm's behavior in the following
scenario: A worm is moving toward an apple. Each time it moves the worm
cuts the distance between itself and the apple by its own body length
until the worm is close enough to enter the apple. The worm can enter
the apple when it is within a body length of the apple. I now I need to
use an iteration control structure but have no idea where to start or
what to do in this one. Can some one help?
You could use either a for loop or a while loop here, but since you are
having problems in this area, a while loop is perhaps easier to understand.
Everything is out in plain sight and nothing "under the covers", you might
say. Besides its easier to write pseudocode for a while loop. How about
translating this to C?

while distance>= worm length
distance = distance - worm length

Where distance is the distance remaining to the apple.
Aug 16 '06 #2

porky008 wrote:
I am taking a beginners class in programming and I am very lost. I need
to design a program that models the worm's behavior in the following
scenario: A worm is moving toward an apple. Each time it moves the worm
cuts the distance between itself and the apple by its own body length
until the worm is close enough to enter the apple. The worm can enter
the apple when it is within a body length of the apple. I now I need to
use an iteration control structure but have no idea where to start or
what to do in this one. Can some one help?
Start by breaking your problem down into smaller problems, eg, write
down with pencil and paper "Move worm:"
position = position + 1

etc

Then translate it into the language you are using.

Aug 16 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Phil | last post: by
5 posts views Thread by Paul Smith | last post: by
18 posts views Thread by Sender | last post: by
2 posts views Thread by antonyliu2002 | last post: by
2 posts views Thread by kamiseq | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.