Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- calculate the volume of a polygon
- local sides = 5
- local length_of_one_side = 8
- local height = 8
- local ex = 5.5
- local unit = "in"
- function removedeci(x)
- local y = tostring(x)
- for i=1,#y do
- if string.sub(y,i,i) == "." then
- if string.sub(y,i+1,i+1) == "0" and string.sub(y,i+2,i+2) == "" then
- return tonumber(string.sub(y,1,i-1))
- end
- end
- end
- return x
- end
- --calculations
- local fric = sides*length_of_one_side
- local frac = tostring(sides)..unit.." * "..length_of_one_side..unit.." = "..removedeci(fric)..unit.."²"
- local fric2 = 0.5*(ex)*(fric)
- local frac2 = "½ * "..ex..unit.." * "..removedeci(fric)..unit.."² = "..removedeci(fric2)..unit.."²"
- local fric3 = fric2*height
- local frac3 = tostring(removedeci(fric2))..unit.."²".." * "..height..unit.." = "..removedeci(fric3)..unit.."³"
- print(frac.."\n"..frac2.."\n"..frac3.."\n----------------------------\nAnswer:")
- print(removedeci(fric3)..unit.."³")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement