The volume of an object is the total space occupied by that object. The volume of a cube is obtained by taking the product of three lengths of the cube.
volume = s * s * s
volume
: This represents the volume of the cube.s
: This represents the length of each side of the cube.# create function to get the volume of a cube def getVolume(lengthOfSide) volume = lengthOfSide * lengthOfSide * lengthOfSide puts "The volume of cube with length of side #{lengthOfSide} is = #{volume}" end # create length of sides of cubes l1 = 23 l2 = 5 l3 = 0.5 l4 = 100 # get the volumes of the cubes getVolume(l1) getVolume(l2) getVolume(l3) getVolume(l4)
getVolume()
, which takes the length of the side of a cube, calculates the volume, and prints the result to the console.RELATED TAGS
CONTRIBUTOR
View all Courses