-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
68 lines (65 loc) · 1.47 KB
/
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package main
import (
"fmt"
"os"
"strconv"
)
// ---------------------------------------------------------
// STORY
//
// Your boss wants you to create a program that will check
// whether a person can watch a particular movie or not.
//
// Imagine that another program provides the age to your
// program. Depending on what you return, the other program
// will issue the tickets to the person automatically.
//
// EXERCISE: Movie Ratings
//
// 1. Get the age from the command-line.
//
// 2. Return one of the following messages if the age is:
// -> Above 17 : "R-Rated"
// -> Between 13 and 17: "PG-13"
// -> Below 13 : "PG-Rated"
//
// RESTRICTIONS:
// 1. If age data is wrong or absent let the user know.
// 2. Do not accept negative age.
//
// BONUS:
// 1. BONUS: Use if statements only twice throughout your program.
// 2. BONUS: Use an if statement only once.
//
// EXPECTED OUTPUT
// go run main.go 18
// R-Rated
//
// go run main.go 17
// PG-13
//
// go run main.go 12
// PG-Rated
//
// go run main.go
// Requires age
//
// go run main.go -5
// Wrong age: "-5"
// ---------------------------------------------------------
func main() {
arg:=os.Args[1:]
if(len(arg)!=1){
fmt.Println("Requires age")
return
}
if age,err:=strconv.Atoi(arg[0]);err!=nil || age<0{
fmt.Printf("Wrong age %d",age)
} else if age>=18{
fmt.Println("R-Rated")
} else if age>=13 && age<18{
fmt.Println("PG-13")
} else{
fmt.Println("PG-Rated")
}
}