Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Date Completed: July 13, 2017
- // Purpose: Calculating time until topsoil is unsuitable for farming
- // This line makes the button, btnCalculate wait for a mouse click
- // When the button is clicked, the determineResult function is called
- btnCalculate.addEventListener(MouseEvent.CLICK, determineResult);
- // This is the determineResult function
- // e:MouseEvent is the click event experienced by the button
- // void indicates that the function does not return a value
- function determineResult(e:MouseEvent):void
- {
- //Declare the variables
- var Depth:Number;
- var Counter:Number = 0;
- //Set the variables to the values
- Depth = 30
- //Introduce the while statement for calculating the time until topsoil is unsuitable for farming
- while (Depth >= 9.25)
- {
- Depth = (Depth - (Depth * 0.01)) + 0.005;
- lblResult.text = "It will take " + Counter + " years for the soil to erode to a depth that crops will not grow ";
- Counter++;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement