2023-10-25 11:55:04 -04:00
|
|
|
package main
|
|
|
|
|
|
|
|
import "fmt"
|
|
|
|
|
|
|
|
func paintNeeded(width float64, height float64) (paintNeededCalculated float64, anError error) {
|
|
|
|
area := width * height
|
|
|
|
if width < 0.0 {
|
2024-02-03 11:11:54 -05:00
|
|
|
return 0, fmt.Errorf("a width of %0.2f is invalid", width)
|
2023-10-25 11:55:04 -04:00
|
|
|
}
|
|
|
|
if height < 0.0 {
|
2024-02-03 11:11:54 -05:00
|
|
|
return 0, fmt.Errorf("a height of %0.2f is invalid", height)
|
2023-10-25 11:55:04 -04:00
|
|
|
}
|
|
|
|
return area / 10.0, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func printListersNeeded(amount float64) {
|
|
|
|
fmt.Printf("%.2f liters needed\n", amount)
|
|
|
|
}
|
|
|
|
|
|
|
|
func wallArea() {
|
|
|
|
var amount, total float64
|
|
|
|
amount, err := paintNeeded(4.2, 3.0)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
} else {
|
|
|
|
printListersNeeded(amount)
|
|
|
|
}
|
|
|
|
total += amount
|
|
|
|
amount, err = paintNeeded(-5.2, 3.5)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
} else {
|
|
|
|
printListersNeeded(amount)
|
|
|
|
}
|
|
|
|
total += amount
|
|
|
|
amount, err = paintNeeded(5.2, 5.0)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
} else {
|
|
|
|
printListersNeeded(amount)
|
|
|
|
}
|
|
|
|
total += amount
|
|
|
|
fmt.Printf("Total: %.2f liters\n", total)
|
|
|
|
}
|