Mastering-Go-Second-Edition/ch06/functions.go
2019-01-10 22:09:57 +02:00

39 lines
593 B
Go

package main
import (
"fmt"
"os"
"strconv"
)
func doubleSquare(x int) (int, int) {
return x * 2, x * x
}
func main() {
arguments := os.Args
if len(arguments) != 2 {
fmt.Println("The program needs 1 argument!")
return
}
y, err := strconv.Atoi(arguments[1])
if err != nil {
fmt.Println(err)
return
}
square := func(s int) int {
return s * s
}
fmt.Println("The square of", y, "is", square(y))
double := func(s int) int {
return s + s
}
fmt.Println("The double of", y, "is", double(y))
fmt.Println(doubleSquare(y))
d, s := doubleSquare(y)
fmt.Println(d, s)
}