Compare commits
No commits in common. "f68fdf3d9b44fe9fda8b9cd59325368b29eb3b3b" and "5cbc048b51ee2b367f17182c5a2d75b203e5d2be" have entirely different histories.
f68fdf3d9b
...
5cbc048b51
@ -3,7 +3,7 @@ package main
|
||||
import "fmt"
|
||||
|
||||
func sum(numbers ...int) int {
|
||||
var sum = 0
|
||||
var sum int = 0
|
||||
|
||||
for _, number := range numbers {
|
||||
sum += number
|
||||
|
@ -14,7 +14,7 @@ func averageCalc(numbers ...float64) float64 {
|
||||
return sum / float64(len(numbers))
|
||||
}
|
||||
|
||||
func main() {
|
||||
func averageHeadFirstVariadic() {
|
||||
arguments := os.Args[1:]
|
||||
var numbers []float64
|
||||
for _, argument := range arguments {
|
||||
@ -22,5 +22,5 @@ func main() {
|
||||
Error(err)
|
||||
numbers = append(numbers, number)
|
||||
}
|
||||
fmt.Printf("Average: %0.2f\n", averageCalc(numbers...))
|
||||
fmt.Printf("Average: %0.2\n", averageCalc(numbers...))
|
||||
}
|
||||
|
@ -6,13 +6,13 @@ import (
|
||||
)
|
||||
|
||||
func maximum(numbers ...float64) float64 {
|
||||
maxNumber := math.Inf(-1)
|
||||
max := math.Inf(-1)
|
||||
for _, number := range numbers {
|
||||
if number > maxNumber {
|
||||
maxNumber = number
|
||||
if number > max {
|
||||
max = number
|
||||
}
|
||||
}
|
||||
return maxNumber
|
||||
return max
|
||||
}
|
||||
|
||||
func inRange(min float64, max float64, numbers ...float64) []float64 {
|
||||
|
@ -5,10 +5,10 @@ import "fmt"
|
||||
func paintNeeded(width float64, height float64) (paintNeededCalculated float64, anError error) {
|
||||
area := width * height
|
||||
if width < 0.0 {
|
||||
return 0, fmt.Errorf("a width of %0.2f is invalid", width)
|
||||
return 0, fmt.Errorf("a width of %0.2f is invalid.", width)
|
||||
}
|
||||
if height < 0.0 {
|
||||
return 0, fmt.Errorf("a height of %0.2f is invalid", height)
|
||||
return 0, fmt.Errorf("a height of %0.2f is invalid.", height)
|
||||
}
|
||||
return area / 10.0, nil
|
||||
}
|
||||
|
@ -15,10 +15,7 @@ func OpenFile(fileName string) (*os.File, error) {
|
||||
|
||||
func CloseFile(file *os.File) {
|
||||
fmt.Println("Closing file")
|
||||
err := file.Close()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
file.Close()
|
||||
}
|
||||
|
||||
func GetFloats(fileName string) ([]float64, error) {
|
||||
|
Loading…
Reference in New Issue
Block a user