{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Iteration Control Structures

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

Info icon This 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
Image of page 1

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

View Full Document Right 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
Image of page 2
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

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern