added average variadic to set

This commit is contained in:
John O'Keefe 2023-11-04 13:09:04 -04:00
parent 66f06e8dd9
commit 805c0a7e21
2 changed files with 22 additions and 0 deletions

View File

@ -0,0 +1,16 @@
package main
import "fmt"
func average(numbers ...float64) float64 {
var sum float64 = 0
for _, number := range numbers {
sum += number
}
return sum / float64(len(numbers))
}
func averageVariadic() {
fmt.Println(average(100, 50))
fmt.Println(average(90.7, 89.7, 98.5, 92.3))
}

View File

@ -32,8 +32,12 @@ func main() {
averageMySolution()
case "Get the Average Head First Solution":
averageHeadFirstSolution()
case "Get the Average Variadic":
averageVariadic()
case "Slices":
slices()
case "Variadic Functions":
variadic()
}
return nil
})
@ -48,7 +52,9 @@ func main() {
menu.Option("Convert To Celsius", nil, false, nil)
menu.Option("Get the Average My Solution", nil, false, nil)
menu.Option("Get the Average Head First Solution", nil, false, nil)
menu.Option("Get the Average Variadic", nil, false, nil)
menu.Option("Slices", nil, false, nil)
menu.Option("Variadic Functions", nil, false, nil)
err := menu.Run()
if err != nil {
log.Fatal(err)