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
35
package main

import (
	"errors"
	"fmt"
)

func age(urAge int) (int, string, error) {

	if urAge > 120 || urAge < 0 {
		return -1, "", errors.New("Invalid age")
	} else if urAge >= 0 && urAge <= 2 {
		return urAge, "Infant", nil
	} else if urAge > 2 && urAge <= 12 {
		return urAge, "Child", nil
	} else if urAge > 12 && urAge <= 19 {
		return urAge, "Teenager", nil

	} else {
		return urAge, "Adult", nil
	}
}
func main() {
    
    var input int
    fmt.Println("Enter your age: ")
    fmt.Scanf("%d", &input)

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