Kalkulator Dasar di Go
package main
import (
"fmt"
)
func main() {
var x int
var y int
var ope string
fmt.Print("First digits: ")
fmt.Scanln(&x)
fmt.Print("Operation: ")
fmt.Scanln(&ope)
fmt.Print("Second digits: ")
fmt.Scanln(&y)
var sum int = maths(x, ope, y)
fmt.Println(x, ope, y, "=", sum)
}
func maths(x int, ope string, y int) int {
if ope == "+" {
return x + y
} else if ope == "-" {
return x / y
} else if ope == "x" || ope == "*" {
return x * y
} else if ope == "/" {
return x / y
} else if ope == "^" || ope == "**" {
return x ^ y
}
return 1
}
Grotesque Gerenuk