completed average function
This commit is contained in:
parent
02c95ceb05
commit
f4b408cf92
@ -2,9 +2,21 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
func average2() {
|
func main() {
|
||||||
fmt.Println(os.Args)
|
arguments := os.Args[1:]
|
||||||
|
var sum float64 = 0
|
||||||
|
for _, argument := range arguments {
|
||||||
|
number, err := strconv.ParseFloat(argument, 64)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
sum += number
|
||||||
|
}
|
||||||
|
sampleCount := float64(len(arguments))
|
||||||
|
fmt.Printf("Average: %0.2f\n", sum/sampleCount)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user