-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinterfaces_t1.go
52 lines (45 loc) · 998 Bytes
/
interfaces_t1.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
package main
import "fmt"
func main() {
var value1, value2, operation interface{}
value1 = true
value2 = 3.6
operation = "/"
if testVar(value1) == true && testVar(value2) == true && testOperator(operation) == true {
switch operation {
case "+":
res := value1.(float64) + value2.(float64)
fmt.Printf("%.4f", res)
break
case "-":
res := value1.(float64) - value2.(float64)
fmt.Printf("%.4f", res)
break
case "*":
res := value1.(float64) * value2.(float64)
fmt.Printf("%.4f", res)
break
case "/":
res := value1.(float64) / value2.(float64)
fmt.Printf("%.4f", res)
break
}
}
}
func testVar(i interface{}) bool {
if _, ok := i.(float64); ok {
return true
}
fmt.Printf("value=%v: %T", i, i)
return false
}
func testOperator(i interface{}) bool {
if v, ok := i.(string); ok {
if v == "+" || v == "-" || v == "*" || v == "/" {
return true
} else {
fmt.Println("неизвестная операция")
return false
}
}
}