Advertisement
Ozzypig

Part 2 - Exercise 1 Solution

May 21st, 2018
314
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.68 KB | None | 0 0
  1. -- Problem: It's a hot day, and staying hydrated is important. You
  2. -- have a cylindrical water bottle with a height and radius. You
  3. -- plan on going on an adventure which requires you to drink 100
  4. -- units of water. Given the dimensions of some bottle, print
  5. -- "Hydrated" if the bottle will hold enough water for you to stay
  6. -- hydrated during the adventure. Otherwise, print "Thirsty".
  7. -- Solution: Volume of a cylinder is base times height. Compare this
  8. -- number to 100 using >=.
  9. -- Input
  10. height = 10
  11. radius = 2
  12. pi = 3.14159
  13. -- Calculation
  14. bottle_volume = pi * radius * radius * height
  15. -- Output
  16. if bottle_volume >= 100 then
  17.     print("Hydrated")
  18. else
  19.     print("Thirsty")
  20. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement