add: unfinished code. people are having problems
This commit is contained in:
32
14-arrays/_experimental/11-avg/solution/main.go
Normal file
32
14-arrays/_experimental/11-avg/solution/main.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func main() {
|
||||
args := os.Args[1:]
|
||||
|
||||
var (
|
||||
sum float64
|
||||
nums [5]float64
|
||||
total float64
|
||||
)
|
||||
|
||||
for i, v := range args {
|
||||
n, err := strconv.ParseFloat(v, 64)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
total++
|
||||
nums[i] = n
|
||||
sum += n
|
||||
}
|
||||
|
||||
fmt.Println("Your numbers:", nums)
|
||||
fmt.Printf("(Only %g of them were valid)\n", total)
|
||||
fmt.Println("Average:", sum/total)
|
||||
}
|
Reference in New Issue
Block a user