2023-10-25 11:55:04 -04:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
|
2024-01-11 11:18:00 -05:00
|
|
|
"git.linuxhg.com/Go_Training/datafile"
|
|
|
|
"git.linuxhg.com/Go_Training/keyboard"
|
2023-10-25 11:55:04 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
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)
|
|
|
|
}
|