Compare commits
3 Commits
5cbc048b51
...
main
Author | SHA1 | Date | |
---|---|---|---|
ce125279ca | |||
f68fdf3d9b | |||
56fa94fce7 |
@ -3,7 +3,7 @@ package main
|
|||||||
import "fmt"
|
import "fmt"
|
||||||
|
|
||||||
func sum(numbers ...int) int {
|
func sum(numbers ...int) int {
|
||||||
var sum int = 0
|
var sum = 0
|
||||||
|
|
||||||
for _, number := range numbers {
|
for _, number := range numbers {
|
||||||
sum += number
|
sum += number
|
||||||
|
@ -14,7 +14,7 @@ func averageCalc(numbers ...float64) float64 {
|
|||||||
return sum / float64(len(numbers))
|
return sum / float64(len(numbers))
|
||||||
}
|
}
|
||||||
|
|
||||||
func averageHeadFirstVariadic() {
|
func main() {
|
||||||
arguments := os.Args[1:]
|
arguments := os.Args[1:]
|
||||||
var numbers []float64
|
var numbers []float64
|
||||||
for _, argument := range arguments {
|
for _, argument := range arguments {
|
||||||
@ -22,5 +22,5 @@ func averageHeadFirstVariadic() {
|
|||||||
Error(err)
|
Error(err)
|
||||||
numbers = append(numbers, number)
|
numbers = append(numbers, number)
|
||||||
}
|
}
|
||||||
fmt.Printf("Average: %0.2\n", averageCalc(numbers...))
|
fmt.Printf("Average: %0.2f\n", averageCalc(numbers...))
|
||||||
}
|
}
|
||||||
|
@ -48,6 +48,7 @@ func (m testModel) View() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func terminalTest() {
|
func terminalTest() {
|
||||||
|
//goland:noinspection SpellCheckingInspection,SpellCheckingInspection
|
||||||
items := []list.Item{
|
items := []list.Item{
|
||||||
item{title: "Raspberry Pi’s", desc: "I have ’em all over my house"},
|
item{title: "Raspberry Pi’s", desc: "I have ’em all over my house"},
|
||||||
item{title: "Nutella", desc: "It's good on toast"},
|
item{title: "Nutella", desc: "It's good on toast"},
|
||||||
|
@ -6,13 +6,13 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func maximum(numbers ...float64) float64 {
|
func maximum(numbers ...float64) float64 {
|
||||||
max := math.Inf(-1)
|
maxNumber := math.Inf(-1)
|
||||||
for _, number := range numbers {
|
for _, number := range numbers {
|
||||||
if number > max {
|
if number > maxNumber {
|
||||||
max = number
|
maxNumber = number
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return max
|
return maxNumber
|
||||||
}
|
}
|
||||||
|
|
||||||
func inRange(min float64, max float64, numbers ...float64) []float64 {
|
func inRange(min float64, max float64, numbers ...float64) []float64 {
|
||||||
|
@ -5,15 +5,15 @@ import "fmt"
|
|||||||
func paintNeeded(width float64, height float64) (paintNeededCalculated float64, anError error) {
|
func paintNeeded(width float64, height float64) (paintNeededCalculated float64, anError error) {
|
||||||
area := width * height
|
area := width * height
|
||||||
if width < 0.0 {
|
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 {
|
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
|
return area / 10.0, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func printListersNeeded(amount float64) {
|
func printLitersNeeded(amount float64) {
|
||||||
fmt.Printf("%.2f liters needed\n", amount)
|
fmt.Printf("%.2f liters needed\n", amount)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -23,21 +23,21 @@ func wallArea() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
} else {
|
} else {
|
||||||
printListersNeeded(amount)
|
printLitersNeeded(amount)
|
||||||
}
|
}
|
||||||
total += amount
|
total += amount
|
||||||
amount, err = paintNeeded(-5.2, 3.5)
|
amount, err = paintNeeded(-5.2, 3.5)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
} else {
|
} else {
|
||||||
printListersNeeded(amount)
|
printLitersNeeded(amount)
|
||||||
}
|
}
|
||||||
total += amount
|
total += amount
|
||||||
amount, err = paintNeeded(5.2, 5.0)
|
amount, err = paintNeeded(5.2, 5.0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
} else {
|
} else {
|
||||||
printListersNeeded(amount)
|
printLitersNeeded(amount)
|
||||||
}
|
}
|
||||||
total += amount
|
total += amount
|
||||||
fmt.Printf("Total: %.2f liters\n", total)
|
fmt.Printf("Total: %.2f liters\n", total)
|
||||||
|
@ -15,7 +15,10 @@ func OpenFile(fileName string) (*os.File, error) {
|
|||||||
|
|
||||||
func CloseFile(file *os.File) {
|
func CloseFile(file *os.File) {
|
||||||
fmt.Println("Closing file")
|
fmt.Println("Closing file")
|
||||||
file.Close()
|
err := file.Close()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetFloats(fileName string) ([]float64, error) {
|
func GetFloats(fileName string) ([]float64, error) {
|
||||||
|
Reference in New Issue
Block a user