Advertisement
BobMe

Polygon Volume CALLLLLC

Dec 6th, 2019
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. -- calculate the volume of a polygon
  2.  
  3. local sides = 5
  4. local length_of_one_side = 8
  5. local height = 8
  6. local ex = 5.5
  7. local unit = "in"
  8.  
  9. function removedeci(x)
  10. local y = tostring(x)
  11. for i=1,#y do
  12. if string.sub(y,i,i) == "." then
  13. if string.sub(y,i+1,i+1) == "0" and string.sub(y,i+2,i+2) == "" then
  14. return tonumber(string.sub(y,1,i-1))
  15. end
  16. end
  17. end
  18. return x
  19. end
  20.  
  21.  
  22. --calculations
  23. local fric = sides*length_of_one_side
  24. local frac = tostring(sides)..unit.." * "..length_of_one_side..unit.." = "..removedeci(fric)..unit.."²"
  25. local fric2 = 0.5*(ex)*(fric)
  26. local frac2 = "½ * "..ex..unit.." * "..removedeci(fric)..unit.."² = "..removedeci(fric2)..unit.."²"
  27. local fric3 = fric2*height
  28. local frac3 = tostring(removedeci(fric2))..unit.."²".." * "..height..unit.." = "..removedeci(fric3)..unit.."³"
  29. print(frac.."\n"..frac2.."\n"..frac3.."\n----------------------------\nAnswer:")
  30.  
  31. print(removedeci(fric3)..unit.."³")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement