Files
learngo/14-arrays/_experimental/11-avg/solution/main.go

33 lines
413 B
Go
Raw Normal View History

package main
import (
"fmt"
"os"
"strconv"
)
func main() {
args := os.Args[1:]
var (
sum float64
nums [5]float64
total float64
)
for i, v := range args {
n, err := strconv.ParseFloat(v, 64)
if err != nil {
continue
}
total++
nums[i] = n
sum += n
}
fmt.Println("Your numbers:", nums)
fmt.Printf("(Only %g of them were valid)\n", total)
fmt.Println("Average:", sum/total)
}