logo image

Go language program to take birth year and tells age

35


Following program shows you how to take birth year and tells age. In this program we get birth year from user and tells their age using currentYear - birthYear

package main

import "fmt"

func main() {
  var birthYear int
  var age int
  fmt.Println("Please enter your date of birth:")
  fmt.Scanf("%d", &birthYear)
  age = 2018 - birthYear
  fmt.Println("Your age is" ,age)
}

Output:

Please enter your date of birth:
 1985
Your age is 33