Finished exercise and added getAverage()
This commit is contained in:
parent
d3400c86ee
commit
a806cecefa
|
@ -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.
Loading…
Reference in New Issue