Advertisement
BOT_Yokel

ICS3U1 Unit 1 Activity 6: Question 6

Jul 13th, 2017
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Date Completed: July 13, 2017
  2. // Purpose: Calculating time until topsoil is unsuitable for farming
  3.  
  4. // This line makes the button, btnCalculate wait for a mouse click
  5. // When the button is clicked, the determineResult function is called
  6. btnCalculate.addEventListener(MouseEvent.CLICK, determineResult);
  7.  
  8. // This is the determineResult function
  9. // e:MouseEvent is the click event experienced by the button
  10. // void indicates that the function does not return a value
  11. function determineResult(e:MouseEvent):void
  12.  
  13. {
  14.     //Declare the variables
  15.     var Depth:Number;
  16.     var Counter:Number = 0;
  17.    
  18.     //Set the variables to the values
  19.     Depth = 30
  20.    
  21.     //Introduce the while statement for calculating the time until topsoil is unsuitable for farming
  22.     while (Depth >= 9.25)
  23.     {
  24.         Depth = (Depth - (Depth * 0.01)) + 0.005;
  25.         lblResult.text  = "It will take " + Counter + " years for the soil to erode to a depth that crops will not grow ";
  26.         Counter++;
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement