Exercises & activities from the go workshop provided by Packt: https://courses.packtpub.com/courses/go
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

43 lines
742 B

package main
import (
"errors"
"fmt"
)
var (
ErrHourlyRate = errors.New("invalid hourly rate")
ErrHoursWorked = errors.New("invalid hours worked per week")
)
func main() {
pay := payDay(81, 50)
fmt.Println(pay)
}
func payDay(hoursWorked, hourlyRate int) int {
report := func() {
fmt.Printf("hoursWorked: %d\nhourlyRate: %d\n", hoursWorked, hourlyRate)
}
defer report()
if hourlyRate < 10 || hourlyRate > 75 {
panic(ErrHourlyRate)
}
if hoursWorked < 0 || hoursWorked > 80 {
panic(ErrHoursWorked)
}
if hoursWorked > 40 {
hoursOver := hoursWorked - 40
overTime := hoursOver * 2
regularPay := 40 * hourlyRate
return regularPay + overTime
}
return hoursWorked * hourlyRate
}