fix average package

This commit is contained in:
Archie Fox
2025-01-30 20:55:42 +03:00
parent f9af59f4d1
commit bb93fd5d7b
3 changed files with 46 additions and 4 deletions

View File

@@ -1,13 +1,21 @@
package main
import "fmt"
import (
"fmt"
"headfirstgo/headfirstgo/chapter5/datafile"
"log"
)
func main() {
numbers := [3]float64{71.8, 56.2, 89.5}
numbers, err := datafile.GetFloats("data.txt")
if err != nil {
log.Fatal(err)
}
var sum float64 = 0
for _, num := range numbers {
sum += num
}
fmt.Println(sum)
sampleCount := float64(len(numbers))
fmt.Printf("Average: %0.2f\n", sum/sampleCount)
}