27 lines
491 B
Go
27 lines
491 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"strconv"
|
|
)
|
|
|
|
func averageCalc(numbers ...float64) float64 {
|
|
var sum float64 = 0
|
|
for _, number := range numbers {
|
|
sum += number
|
|
}
|
|
return sum / float64(len(numbers))
|
|
}
|
|
|
|
func averageHeadFirstVariadic() {
|
|
arguments := os.Args[1:]
|
|
var numbers []float64
|
|
for _, argument := range arguments {
|
|
number, err := strconv.ParseFloat(argument, 64)
|
|
Error(err)
|
|
numbers = append(numbers, number)
|
|
}
|
|
fmt.Printf("Average: %0.2\n", averageCalc(numbers...))
|
|
}
|