The cinema checks the rating: "G" is for everyone; "PG-13" needs age 13 or more, or a parent along (withParent); "18" needs age 18 or more, parent or not. Write CanWatch(age, rating, withParent) to return true if they may watch. The rating is always one of these three.
CanWatch(8, "G", false)→TrueCanWatch(10, "PG-13", true)→TrueCanWatch(16, "18", true)→Falsefunc CanWatch(age int, rating string, withParent bool) boolpackage main
func CanWatch(age int, rating string, withParent bool) bool {
if rating == "G" {
return true
}
// your code here: one if each for "PG-13" and "18"; return true when allowed
return false
}
Run tries the examples. When they look right, Submit.