package main
import (
"fmt"
)
/*
Calculate the volume of a cube in Go
------------------------------------
A cube has equal side lengths. If each side has length "side",
the volume is:
volume = side * side * side
Go does not have a built‑in exponent operator, and using
math.Pow for a simple cube is unnecessary. Multiplication
is clear and efficient.
*/
// cubeVolume computes the volume of a cube.
// side: length of one side (must be non‑negative)
func cubeVolume(side float64) float64 {
if side < 0 {
panic("Side length must be non‑negative")
}
// Compute side³ using multiplication
return side * side * side
}
func main() {
var side float64 = 6.0
fmt.Println("Side length:", side)
fmt.Println("Volume of cube:", cubeVolume(side))
}
/*
run:
Side length: 6
Volume of cube: 216
*/