bornwithnoname
01-29-2008, 09:29 PM
Here is the problem
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.
Here is my working solution. This is not an exercise in writing a program in a specfic language, but an exercise in how to write a program.
input module
declare Wormlength, AppleDistance as real
write what is the length of the worm?
input WormLength
write What is the distance to the apple?
input AppleDistance
While AppleDistance > Wormlength
AppleDistance - Wormlength
This is where I start running into problems. I know I need some kind of loop function and I need away to keep track of the distance covered.
Any help or direction would be great.
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.
Here is my working solution. This is not an exercise in writing a program in a specfic language, but an exercise in how to write a program.
input module
declare Wormlength, AppleDistance as real
write what is the length of the worm?
input WormLength
write What is the distance to the apple?
input AppleDistance
While AppleDistance > Wormlength
AppleDistance - Wormlength
This is where I start running into problems. I know I need some kind of loop function and I need away to keep track of the distance covered.
Any help or direction would be great.