mirror of
https://github.com/bootdotdev/fcc-learn-golang-assets.git
synced 2025-12-18 19:21:17 +00:00
first
This commit is contained in:
33
course/6-errors/exercises/5-errors_package/code.go
Normal file
33
course/6-errors/exercises/5-errors_package/code.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func divide(x, y float64) (float64, error) {
|
||||
if y == 0 {
|
||||
// ?
|
||||
}
|
||||
return x / y, nil
|
||||
}
|
||||
|
||||
// don't edit below this line
|
||||
|
||||
func test(x, y float64) {
|
||||
defer fmt.Println("====================================")
|
||||
fmt.Printf("Dividing %.2f by %.2f ...\n", x, y)
|
||||
quotient, err := divide(x, y)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
fmt.Printf("Quotient: %.2f\n", quotient)
|
||||
}
|
||||
|
||||
func main() {
|
||||
test(10, 0)
|
||||
test(10, 2)
|
||||
test(15, 30)
|
||||
test(6, 3)
|
||||
}
|
||||
Reference in New Issue
Block a user