commit c7298061fa9bb0ae38dcfc8e70442343fd6cb2b7
Author: NunoSempere <nuno.semperelh@protonmail.com>
Date: Fri, 10 May 2024 19:05:03 +0100
initial template with help of gpt4
Diffstat:
| A | main | | | 0 | |
| A | main.go | | | 50 | ++++++++++++++++++++++++++++++++++++++++++++++++++ |
2 files changed, 50 insertions(+), 0 deletions(-)
diff --git a/main b/main
Binary files differ.
diff --git a/main.go b/main.go
@@ -0,0 +1,50 @@
+package main
+
+import (
+ "bufio"
+ "fmt"
+ "os"
+ "strconv"
+ "strings"
+)
+
+func main() {
+ reader := bufio.NewReader(os.Stdin)
+
+ // First request
+ fmt.Println("Enter two floats separated by a space:")
+ input, _ := reader.ReadString('\n')
+ input = strings.TrimSpace(input)
+ fmt.Println("=>", input)
+
+ // Subsequent requests
+ for {
+ fmt.Println("Enter another two floats separated by a space:")
+ input, _ = reader.ReadString('\n')
+ input = strings.TrimSpace(input)
+
+ if input == "" {
+ break // Exit if no input is given
+ }
+
+ // Split the input and apply the formula
+ tokens := strings.Split(input, " ")
+ if len(tokens) != 2 {
+ fmt.Println("Please enter exactly two floats.")
+ continue
+ }
+
+ firstNum, err1 := strconv.ParseFloat(tokens[0], 64)
+ secondNum, err2 := strconv.ParseFloat(tokens[1], 64)
+ if err1 != nil || err2 != nil {
+ fmt.Println("Invalid input. Please ensure you enter two floats.")
+ continue
+ }
+
+ // Example formula: firstNum * 0.5 and secondNum * 10
+ result1 := firstNum * 0.5
+ result2 := secondNum * 10
+
+ fmt.Printf("=> %.1f %.1f\n", result1, result2)
+ }
+}