45 lines
		
	
	
		
			923 B
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			45 lines
		
	
	
		
			923 B
		
	
	
	
		
			Go
		
	
	
	
	
	
package main
 | 
						|
 | 
						|
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)
 | 
						|
	}
 | 
						|
	if height < 0.0 {
 | 
						|
		return 0, fmt.Errorf("a height of %0.2f is invalid.", height)
 | 
						|
	}
 | 
						|
	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)
 | 
						|
}
 |