Skip to content

Instantly share code, notes, and snippets.

@fadhil-riyanto
Created October 15, 2020 02:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fadhil-riyanto/cfbcad6e76038bec5c4706566d0ed968 to your computer and use it in GitHub Desktop.
Save fadhil-riyanto/cfbcad6e76038bec5c4706566d0ed968 to your computer and use it in GitHub Desktop.
This simply calculator CLI with golang languange programming
package main
import "fmt"
func main() {
var operator string
var number1, number2 int
fmt.Print("Please enter First number: ")
fmt.Scanln(&number1)
fmt.Print("Please enter Second number: ")
fmt.Scanln(&number2)
fmt.Print("Please enter Operator (+,-,/,%,*):")
fmt.Scanln(&operator)
output := 0
switch operator {
case "+":
output = number1 + number2
break
case "-":
output = number1 - number2
case "*":
output = number1 * number2
case "/":
output = number1 / number2
case "%":
output = number1 % number2
default:
fmt.Println("Invalid Operation")
}
fmt.Printf("%d %s %d = %d", number1, operator, number2, output)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment