Files
  • main.go
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package main

import (
	"errors"
	"fmt"
)

func age(urAge int) (string, error) {
    switch {
    case urAge < 0 || urAge > 120:
        return "", errors.New("Invalid age")
    case urAge <= 2:
        return "Infant", nil
    case urAge <= 12:
        return "Child", nil
    case urAge <= 19:
        return "Teenager", nil
    default:
        return "Adult", nil
    }
}
func main() {
    
    var input int
    fmt.Println("Enter your age: ")
    fmt.Scanf("%d", &input)

	if b, e := age(input); e != nil {
    fmt.Println("Error: ", e)
    } else {
    fmt.Println("Age: ", input)
    fmt.Println("Classification: ", b)
    }
}
go version go1.9.4 linux/amd64