Advertisement
Guest User

Untitled

a guest
Dec 8th, 2014
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. Module Module1
  2. Const NUM_CARROTS As Integer = 10000
  3. Const OFFSET_WIDTH As Single = 1254.8F
  4. Const PLANT_INTERVAL As Single = 1.25F
  5. Dim carrot_pos(NUM_CARROTS - 1) As Single
  6.  
  7. Sub plant_carrot(ByVal idx As Integer)
  8. carrot_pos(idx) = OFFSET_WIDTH + idx * PLANT_INTERVAL
  9. End Sub
  10. Sub plant_carrots()
  11. For i = 0 To NUM_CARROTS - 1
  12. plant_carrot(i)
  13. Next
  14. End Sub
  15. Sub print_carrots()
  16. For i = 0 To NUM_CARROTS - 1
  17. Console.WriteLine("Carrot {0} goes to {1:0.00} inches\n", i, carrot_pos(i))
  18. Next
  19. End Sub
  20. Function is_planted_ok(ByVal idx As Integer) As Boolean
  21. Return Math.Round(carrot_pos(idx) - carrot_pos(idx - 1), 2) = PLANT_INTERVAL
  22. End Function
  23. Sub test_carrots()
  24. Dim num_bad As Integer = 0
  25. For i = 1 To NUM_CARROTS - 1
  26. If Not is_planted_ok(i) Then
  27. Console.WriteLine("The carrot {0} is planted incorreclty!!!", i)
  28. num_bad += 1
  29. End If
  30. Next
  31. If num_bad = 0 Then
  32. Console.WriteLine("All carrots placed well!!!!")
  33. Else
  34. Console.WriteLine("{0} of {1} carrots placed incorrectly... : (", num_bad, NUM_CARROTS)
  35. End If
  36. End Sub
  37. Sub Main()
  38. plant_carrots()
  39. 'print_carrots()
  40. test_carrots()
  41. End Sub
  42.  
  43. End Module
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement