-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalculator.go
124 lines (87 loc) · 1.65 KB
/
calculator.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
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
package main
import (
"fmt"
)
func readUserChoice() int {
fmt.Println("Please select the operation you wish to perform - ")
fmt.Println("1. Addition")
fmt.Println("2. Subtraction")
fmt.Println("3. Multiplication")
fmt.Println("4. Division")
fmt.Println("5. Modulation")
fmt.Print("Enter your choice now - ")
var choice int
fmt.Scan(&choice)
return choice
}
func readParams(a *int, b *int) {
fmt.Print("Enter First Number - ")
fmt.Scan(a)
fmt.Print("Enter Second Number - ")
fmt.Scan(b)
}
func addition() {
var a = 0
var b = 0
readParams(&a, &b)
fmt.Print("Addition : ")
fmt.Println(a + b)
}
func subtraction() {
var a = 0
var b = 0
readParams(&a, &b)
fmt.Print("Subtraction : ")
fmt.Println(a - b)
}
func multiplication() {
var a = 0
var b = 0
readParams(&a, &b)
fmt.Print("Multiplication : ")
fmt.Println(a * b)
}
func division() {
var a = 0
var b = 0
readParams(&a, &b)
fmt.Print("Division : ")
fmt.Println(a / b)
}
func modulation() {
var a = 0
var b = 0
readParams(&a, &b)
fmt.Print("Modulation : ")
fmt.Println(a % b)
}
func main() {
fmt.Println("************ Welcome to Calculator Service ***********")
var keepUsing = "y"
for keepUsing == "y" || keepUsing == "Y" {
var choice = readUserChoice()
switch choice {
case 1:
addition()
break
case 2:
subtraction()
break
case 3:
multiplication()
break
case 4:
division()
break
case 5:
modulation()
break
default:
fmt.Println("Invalid Choice Made!!! Please try again!!")
break
}
fmt.Print("Do you wish to try again? (Y | N) - ")
fmt.Scanln(&keepUsing)
}
fmt.Println("Thanks for using calculator.")
}