-
Notifications
You must be signed in to change notification settings - Fork 0
/
conditions.go
61 lines (54 loc) · 1.09 KB
/
conditions.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
package main
import (
"fmt"
"io/ioutil"
)
// switch coding
func eval(a,b int, op string) int{
var results int
switch op {
case "+":
results = a + b
case "-":
results = a - b
case "*":
results = a * b
case "/":
results = a / b
default:
panic("unsupported operator: "+ op)
}
return results
}
func grade(score int) string {
g := ""
switch{
case score < 0 && score > 100:
panic(" Wrong score")
case score < 60:
g = "F"
case score < 80:
g = "C"
case score < 90:
g = "B"
case score < 100:
g = "A"
}
return g
}
func readFile(){
const filename = "abc.txt"
if contents, err := ioutil.ReadFile(filename) ; err != nil {
fmt.Println(err)
} else {
fmt.Println("contents : %s \n", string(contents))
}
}
func main(){
readFile()
fmt.Printf(" 4 + 5 = %d \n",eval(4,5,"+"))
fmt.Printf(" 2 - 1 = %d \n",eval(2,1,"-"))
fmt.Printf(" 2 * 2 = %d \n",eval(2,2,"*"))
fmt.Printf(" 10 / 2 = %d \n",eval(10,2,"/"))
fmt.Printf("John grade: %s \n",grade(50))
}