Add main.go
This commit is contained in:
parent
f28545b05e
commit
0ed360d978
71
main.go
Normal file
71
main.go
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import(
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
|
var num1 float64
|
||||||
|
var num2 float64
|
||||||
|
var math string
|
||||||
|
var calculate int
|
||||||
|
|
||||||
|
func get_num(){
|
||||||
|
fmt.Println("num1:")
|
||||||
|
fmt.Scanln(&num1)
|
||||||
|
fmt.Println("num2:")
|
||||||
|
fmt.Scanln(&num2)
|
||||||
|
}
|
||||||
|
|
||||||
|
func get_math_options(){
|
||||||
|
for {
|
||||||
|
fmt.Println("Choose an operator (+ - / *):")
|
||||||
|
fmt.Scanln(&math)
|
||||||
|
|
||||||
|
switch math {
|
||||||
|
case "+":
|
||||||
|
calculate = 1
|
||||||
|
return
|
||||||
|
case "-":
|
||||||
|
calculate = 2
|
||||||
|
return
|
||||||
|
case "/":
|
||||||
|
calculate = 3
|
||||||
|
return
|
||||||
|
case "*":
|
||||||
|
calculate = 4
|
||||||
|
return
|
||||||
|
default:
|
||||||
|
fmt.Println("Invalid input, try again.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func get_numbers(){
|
||||||
|
switch calculate{
|
||||||
|
case 1:
|
||||||
|
fmt.Println(num1 + num2)
|
||||||
|
return
|
||||||
|
case 2:
|
||||||
|
fmt.Println(num1 - num2)
|
||||||
|
return
|
||||||
|
case 3:
|
||||||
|
if num2 == 0 {
|
||||||
|
fmt.Println("Cannot divide by zero")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
fmt.Println(num1 / num2)
|
||||||
|
return
|
||||||
|
case 4:
|
||||||
|
fmt.Println(num1 * num2)
|
||||||
|
return
|
||||||
|
default:
|
||||||
|
fmt.Println("the hell happened here?")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func main(){
|
||||||
|
get_math_options()
|
||||||
|
get_num()
|
||||||
|
fmt.Println("total")
|
||||||
|
get_numbers()
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user