package main import "fmt" /* @ Constellation Clinic 2 (switch) Guess the month of birth constellation according to user input: · Aries (4) Taurus (5) Gemini (6) Cancer (7) Lion (8) Virgin (9) the balance (10) Scorpio (11) shooter (12) Capricorn (1) bottle (2) Pisces (3) Use case a single point which determines the constellation; Use case a single point which determines the set of seasons (spring and autumn) Use free conditions specific case to determine the user Constellation */ main041 function () { fmt.Println ( "Please enter your birth month (1-12)") var month int fmt.Scan(&month) fmt.Printf("month=%d", month) /* For the month of possible values, do a single point of judgment */ switch month { case 1: fmt.Printf ( "% s is a high probability your seat \ n", "Capricorn") case 2: fmt.Printf ( "% s is a high probability your seat \ n", "Aquarius") case 3: fmt.Printf ( "% s is a high probability your seat \ n", "Pisces") case 4: fmt.Printf ( "% s is a high probability your seat \ n", "Aries") case 5: fmt.Printf ( "% s is a high probability your seat \ n", "Taurus") case 6: fmt.Printf ( "% s is a high probability your seat \ n", "Gemini") case 7: fmt.Printf ( "% s is a high probability your seat \ n", "Cancer") case 8: fmt.Printf ( "% s is a high probability your seat \ n", "Lion") case 9: fmt.Printf ( "% s is a high probability your seat \ n", "virgin") case 10: fmt.Printf ( "% s is a high probability your seat \ n", "balance") case 11: fmt.Printf ( "% s is a high probability your seat \ n", "Scorpio") case 12: fmt.Printf ( "% s is a high probability your seat \ n", "Shooter") // value of the month does not fall within any of the above case // default is optional default: fmt.Println ( "You are the legendary Ophiuchus") } } /* Use case a single point which determines the set of seasons (spring and autumn) */ main042 function () { fmt.Println ( "Please enter your birth month (1-12)") var month int fmt.Scan(&month) fmt.Printf("month=%d", month) switch month { case 12, 1, 2: fmt.Println ( "You were born in the winter") case 3, 4, 5: fmt.Println ( "You were born in the spring") case 6, 7, 8: fmt.Println ( "You were born in the summer") case 9, 10, 11: fmt.Println ( "You were born in the fall") default: fmt.Println ( "You were born on Mars") } } /* Use free condition case to determine its season (seasons) */ func main043() { fmt.Println ( "Please enter your birth month (1-12)") var month int fmt.Scan(&month) // objects not explicitly specify the switch, case can determine with any conditions switch { case month >= 3 && month <= 5: fmt.Println ( "You were born in the spring") case month >= 6 && month <= 8: fmt.Println ( "You were born in the summer") case month >= 9 && month <= 11: fmt.Println ( "You were born in the fall") case month == 12 || month == 1 || month == 2: fmt.Println ( "You were born in the winter") default: fmt.Println ( "You were born on Mars") } } / * Use fallthrough forced to scroll to the next branch and execute * / main044 function () { fmt.Println ( "Please enter your birth month (1-12)") var month int fmt.Scan(&month) // objects not explicitly specify the switch, case can determine with any conditions switch { case month >= 3 && month <= 5: fmt.Println ( "You were born in the spring") // next branch to enforce conditions fallthrough case month >= 6 && month <= 8: fmt.Println ( "You were born in the summer") fmt.Println ( "We were born in the first half") fallthrough case month >= 9 && month <= 11: fmt.Println ( "You were born in the fall") // next branch to enforce conditions fallthrough case month == 12 || month == 1 || month == 2: fmt.Println ( "You were born in the winter") fmt.Println ( "We were born in the second half.") default: fmt.Println ( "You were born on Mars") } }