diff --git a/sum-args/main.go b/sum-args/main.go index cb1f770..9ca3f4e 100644 --- a/sum-args/main.go +++ b/sum-args/main.go @@ -15,9 +15,16 @@ func main() { } 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) } - 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 } diff --git a/sum-args/sum-args b/sum-args/sum-args deleted file mode 100755 index c00ed2e..0000000 Binary files a/sum-args/sum-args and /dev/null differ