Solution: circle STDIN with math


Of course you don't need to type in the value if PI yourself. There is a module called math that provides you the value at a much better precision. There is also a function called Pow that can rasie any number to any power.

examples/circle-stdin-math/circle_stdin_math.go
package main

import (
    "fmt"
    "math"
    "strconv"
)

func main() {
    fmt.Println(math.Pi)

    var radiusStr string
    fmt.Print("radius: ")
    fmt.Scan(&radiusStr)

    radius, err := strconv.ParseFloat(radiusStr, 64)
    if err == nil {
        fmt.Println(radius)
        area := math.Pi * math.Pow(radius, 2)
        circumference := 2 * math.Pi * radius
        fmt.Printf("Area: %v\n", area)
        fmt.Printf("Cirumference: %v\n", circumference)
    }
}