-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmathoperator.go
More file actions
93 lines (63 loc) · 1.3 KB
/
mathoperator.go
File metadata and controls
93 lines (63 loc) · 1.3 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// GO program for math operators
package main
import (
"fmt"
"log"
)
func main() {
// read input from key board
var n1, n2 int
//var n int
fmt.Println("Program for math operators")
again := 1
for again != 0 {
fmt.Print(`
Math operation
----------------
1. add
2. subtract
3. multiply
4. divide
0. exit
`)
fmt.Print("Choose your option: ")
_, err := fmt.Scanln(&again)
if err != nil {
fmt.Println("\nGot an error")
log.Fatal(err)
}
if again == 0 {
break
}
fmt.Print("\nEnter first integer number: ")
_, err1 := fmt.Scanln(&n1)
if err1 != nil {
fmt.Println("\nGot an error")
log.Fatal(err)
}
fmt.Print("Enter second integer number: ")
_, err2 := fmt.Scanln(&n2)
if err2 != nil {
fmt.Println("\nGot an error")
log.Fatal(err)
}
fmt.Println()
switch again {
case 1:
fmt.Printf("Addition of %d and %d is: %v", n1, n2, n1+n2)
case 2:
fmt.Printf("Difference between %d and %d is: %v", n1, n2, n1-n2)
case 3:
fmt.Printf("Product of %d and %d is: %v", n1, n2, n1*n2)
case 4:
fmt.Printf("Division of %d by %d is: %v", n1, n2, n1/n2)
default:
fmt.Printf("Invalid option exiting...")
again = 0
}
if err != nil || err2 != nil || err1 != nil {
fmt.Println("\nGot an error")
log.Fatal(err)
}
}
}