forked from ambujraj/hacktoberfest2018
-
Notifications
You must be signed in to change notification settings - Fork 2
/
gocal.go
64 lines (46 loc) · 1.02 KB
/
gocal.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
package main
//importing fmt package for basic functions
import "fmt"
//declaration of variables
var num1 float32
var num2 float32
var operator string
//declaration of functions
func add(a float32, b float32)float32{
return a+b
}
func substract(a float32, b float32)float32{
return a-b
}
func multiply(a float32, b float32)float32{
return a*b
}
func divide(a float32, b float32)float32{
return a/b
}
//main function
func main(){
fmt.Print("Enter No 1: ")
fmt.Scanln(&num1)
fmt.Print("Enter No 2: ")
fmt.Scanln(&num2)
fmt.Print("Enter operator: ")
fmt.Scanln(&operator)
if (operator == "+"){
fmt.Print("Your answer is: ")
fmt.Println(add(num1,num2))
fmt.Println("\n")
}else if (operator == "-"){
fmt.Print("Your answer is: ")
fmt.Println(substract(num1,num2))
fmt.Println("\n")
}else if (operator == "*"){
fmt.Print("Your answer is: ")
fmt.Println(multiply(num1,num2))
fmt.Println("\n")
}else if (operator == "/"){
fmt.Print("Your answer is: ")
fmt.Println(divide(num1,num2))
fmt.Println("\n")
}
}