Finished exercise and added getAverage()

This commit is contained in:
raul 2024-02-17 21:41:21 +01:00
parent d3400c86ee
commit a806cecefa
2 changed files with 9 additions and 2 deletions

View File

@ -15,9 +15,16 @@ func main() {
} }
for i := 1; i < len(os.Args); i++ { for i := 1; i < len(os.Args); i++ {
sum, _ := strconv.Atoi(os.Args[i]) sum, _ := strconv.ParseFloat(os.Args[i], 64)
result = result + float64(sum) result = result + float64(sum)
} }
fmt.Printf("%v\n", result) averageResult := getAverage(result, len(os.Args)-1)
fmt.Printf("Total sum: %.4v\n", result)
fmt.Printf("Average: %.4v\n", averageResult)
}
func getAverage(num float64, quantity int) (finalNum float64) {
finalNum = num / float64(quantity)
return finalNum
} }

Binary file not shown.