could use help on a simple problem

P

porky008

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?
 
O

osmium

porky008 said:
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.
 
K

kshanholtzer

porky008 said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,681
Members
48,796
Latest member
Greg L.

Latest Threads

Top