From 96daf2f7e27e67b1710aab4fc4777a2db56c836b Mon Sep 17 00:00:00 2001 From: ChaosLL1337 Date: Wed, 21 Oct 2026 06:49:20 +0000 Subject: [PATCH] Besser --- go/01-basics/calculator.go | 77 --------------------------------- go/01-basics/calculatorEigen.go | 74 +++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+), 77 deletions(-) create mode 100644 go/01-basics/calculatorEigen.go diff --git a/go/01-basics/calculator.go b/go/01-basics/calculator.go index 92dcdfc..5240c30 100644 --- a/go/01-basics/calculator.go +++ b/go/01-basics/calculator.go @@ -58,80 +58,3 @@ func main() { } } } - - - -package main - -import ( - "fmt" -) - -const ( - opAdd = "add" - opSubtract = "subtract" - opMultiply = "multiply" - opDivide = "divide" - opExit = "exit" -) - -var result float64 - -func add(a, b float64) { - result = a + b -} -func multiply(a, b float64) { - result = a * b -} -func subtract(a, b float64) { - result = a - b -} -func divide(a, b float64) { - result = a / b -} - -func main() { - var x float64 - var y float64 - - //TODO: implement according to README.md - - //the following code just demonstrates how to use fmt.Scan - - for { - fmt.Print("What would you like to do? (add|subtract|divide|multiply|exit)") - var str string - fmt.Scan(&str) - if str == opExit { - break - } else { - - fmt.Print("Please enter a float: ") - fmt.Scan(&x) - - fmt.Print("Please enter a float: ") - fmt.Scan(&y) - - switch str { - case opAdd: - add(x, y) - fmt.Println(result) - case opMultiply: - multiply(x, y) - fmt.Println(result) - case opDivide: - if y == 0 { - fmt.Println("Division by 0 is not possible") - continue - } - divide(x, y) - fmt.Println(result) - case opSubtract: - subtract(x, y) - fmt.Println(result) - default: - fmt.Println("Unknown operation") - } - } - } -} \ No newline at end of file diff --git a/go/01-basics/calculatorEigen.go b/go/01-basics/calculatorEigen.go new file mode 100644 index 0000000..4789620 --- /dev/null +++ b/go/01-basics/calculatorEigen.go @@ -0,0 +1,74 @@ +package main + +import ( + "fmt" +) + +const ( + opAdd = "add" + opSubtract = "subtract" + opMultiply = "multiply" + opDivide = "divide" + opExit = "exit" +) + +var result float64 + +func add(a, b float64) { + result = a + b +} +func multiply(a, b float64) { + result = a * b +} +func subtract(a, b float64) { + result = a - b +} +func divide(a, b float64) { + result = a / b +} + +func main() { + var x float64 + var y float64 + + //TODO: implement according to README.md + + //the following code just demonstrates how to use fmt.Scan + + for { + fmt.Print("What would you like to do? (add|subtract|divide|multiply|exit)") + var str string + fmt.Scan(&str) + if str == opExit { + break + } else { + + fmt.Print("Please enter a float: ") + fmt.Scan(&x) + + fmt.Print("Please enter a float: ") + fmt.Scan(&y) + + switch str { + case opAdd: + add(x, y) + fmt.Println(result) + case opMultiply: + multiply(x, y) + fmt.Println(result) + case opDivide: + if y == 0 { + fmt.Println("Division by 0 is not possible") + continue + } + divide(x, y) + fmt.Println(result) + case opSubtract: + subtract(x, y) + fmt.Println(result) + default: + fmt.Println("Unknown operation") + } + } + } +}