25 lines
525 B
Go
25 lines
525 B
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"strings"
|
||
|
|
||
|
"git.linuxhg.com/john-okeefe/datafile"
|
||
|
"git.linuxhg.com/john-okeefe/keyboard"
|
||
|
)
|
||
|
|
||
|
func averageHeadFirstSolution() {
|
||
|
fmt.Printf("What is the name of the file: ")
|
||
|
fileString, err := keyboard.GetString()
|
||
|
Error(err)
|
||
|
fileString = strings.TrimSpace(fileString)
|
||
|
numbers, err := datafile.GetFloats(fileString)
|
||
|
Error(err)
|
||
|
var sum float64 = 0
|
||
|
for _, number := range numbers {
|
||
|
sum += number
|
||
|
}
|
||
|
sampleCount := float64(len(numbers))
|
||
|
fmt.Printf("Average: %0.2f\n", sum/sampleCount)
|
||
|
}
|