Created
October 9, 2020 12:58
-
-
Save FerdinaKusumah/2e4dd2b2b8e81894a0846e029aa3b987 to your computer and use it in GitHub Desktop.
Complicated if else
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 calculateNumberIf(x, y int, param string) int { | |
if param == "add" { | |
return addNumber(x, y) | |
} else if param == "sub" { | |
return subtractNumber(x, y) | |
} else if param == "div" { | |
return divideNumber(x, y) | |
} else if param == "mul" { | |
return multiplyNumber(x, y) | |
} | |
return 0 | |
} | |
func main() { | |
var x, y = 10, 2 | |
fmt.Println(calculateNumberIf(x, y, "div")) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment