Iteration Control Structures

Iteration Control Structures - End Main Module Input Data...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Running head: ITERATION CONTROL STRUCTURES 1 Iteration Control Structures Lori Babler IT220 November 12, 2010 Stephen Welborn
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
ITERATION CONTROL STRUCTURES 2 Iteration Control Structures 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. Main Module Declare WormLength as Real Declare AppleDistance as Real Declare NewAppleDistance as Real Declare EnterApple as Integer Get User Input WormLength Get User Input AppleDistance Subtract WormLength from AppleDistance Find NewAppleDistance Is NewAppleDistance <= WormLength find EnterApple
Background image of page 2
Background image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: End Main Module Input Data Module Write “Enter Length of Worm in Inches.” Input WormLength Write “Enter Length between Worm and Apple in Inches.” Input AppleDistance End Input Data Module New AppleDistance Module NewAppleDistance = AppleDistance – WormLength End NewAppleDistance Module EnterApple Integer Module ITERATION CONTROL STRUCTURES 3 If NewAppleDistance <= WormLength Then EnterApple = 1 If NewAppleDistance > WormLength Then EnterApple = 2 End EnterApple Integer Module EnterApple Module Call WormLength While EnterApple = 2 NewAppleDistance = NewAppleDistance – WormLength End While While EnterApple = 1 Write “The Worm is now inside of the Apple.” End While End EnterApple Module...
View Full Document

This note was uploaded on 02/21/2012 for the course IT210 IT210 taught by Professor Hh during the Spring '10 term at University of Phoenix.

Page1 / 3

Iteration Control Structures - End Main Module Input Data...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online