Created
October 9, 2020 13:03
-
-
Save FerdinaKusumah/7522e1c21a8f1ae522834bf19e01e542 to your computer and use it in GitHub Desktop.
Complicated switch case
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
func addNumber(x, y int) int { | |
return x + y | |
} | |
func subtractNumber(x, y int) int { | |
return x - y | |
} | |
func divideNumber(x, y int) int { | |
return x / y | |
} | |
func multiplyNumber(x, y int) int { | |
return x * y | |
} | |
func calculateNumberSwitch(x, y int, param string) int { | |
switch param { | |
case "add": | |
return addNumber(x, y) | |
case "sub": | |
return subtractNumber(x, y) | |
case "div": | |
return divideNumber(x, y) | |
case "mul": | |
return divideNumber(x, y) | |
default: | |
return 0 | |
} | |
} | |
func main() { | |
var x, y = 10, 2 | |
fmt.Println(calculateNumberSwitch(x, y, "div")) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment