Easy Design

All About Design

Design Iterations

without comments

design iterations
How do I design a program with iteration control structure?

problem: 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 need input and output. I need the program to do what I stated in the problem. It’s for a class assignment and I don’t know how the design should look like for the worm’s behavior.
Yes I need to input the worm’s body length and its distance to the apple, how many moves it takes. yes yes yes to everything you asked. As far as programming language this is just for the pseudocode stage. thanks
oh yes that looks like what I need to do from my book examples of other designs. Thank you so much!!!!

you ‘re welcome :)

bodyLength = ask user for body length
distance = ask user for distance

nbOfSteps = 0

while(distance > bodyLength) {
distance = distance – bodyLength
nbOfSteps = nbOfSteps + 1
print out “Distance after “+nbOfSteps+” is “+distance
}

after you finished the loop, the worm will have to do an extra step to get into the apple:
nbOfSteps = nbOfSteps + 1
print out “The worm reached the apple after “+nbOfSteps

VanceTran.com Design Iteration


Written by admin

December 2nd, 2009 at 9:47 am

Leave a Reply