I'm new to programming, and trying to write a simple average program in Go.
package main
import (
"fmt"
"os"
)
var numbers []float64
var sum float64 = 0
func main() {
if len(os.Args) > 1 {
numbers = os.Args[1:]
}
fmt.Println("Numbers are: ", numbers)
for _, value := range numbers {
sum += value
}
}
http://play.golang.org/p/TWNltPO71N
when I build the program, I got this error:
prog.go:15: cannot use os.Args[1:] (type []string) as type []float64 in assignment
[process exited with non-zero status]
So how to convert a slice of string to a slice of float numbers? Can I map a convert function to the slice?