commit a2648c8b95f1f7f12d9eeb65b40c77e1220392b0
parent c7298061fa9bb0ae38dcfc8e70442343fd6cb2b7
Author: NunoSempere <nuno.semperelh@protonmail.com>
Date: Fri, 10 May 2024 19:07:36 +0100
second version, again with gpt4 help
Diffstat:
| M | main.go | | | 26 | ++++++++++++++++++++------ |
1 file changed, 20 insertions(+), 6 deletions(-)
diff --git a/main.go b/main.go
@@ -10,12 +10,27 @@ import (
func main() {
reader := bufio.NewReader(os.Stdin)
+ var stored1, stored2 float64 // Variables to store the intermediate results
// First request
fmt.Println("Enter two floats separated by a space:")
input, _ := reader.ReadString('\n')
input = strings.TrimSpace(input)
- fmt.Println("=>", input)
+
+ // Store the first response
+ tokens := strings.Split(input, " ")
+ if len(tokens) != 2 {
+ fmt.Println("Please enter exactly two floats.")
+ return
+ }
+ stored1, err1 := strconv.ParseFloat(tokens[0], 64)
+ stored2, err2 := strconv.ParseFloat(tokens[1], 64)
+ if err1 != nil || err2 != nil {
+ fmt.Println("Invalid input. Please ensure you enter two floats.")
+ return
+ }
+
+ fmt.Printf("=> %.1f %.1f\n", stored1, stored2)
// Subsequent requests
for {
@@ -27,7 +42,6 @@ func main() {
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.")
@@ -41,10 +55,10 @@ func main() {
continue
}
- // Example formula: firstNum * 0.5 and secondNum * 10
- result1 := firstNum * 0.5
- result2 := secondNum * 10
+ // Example operation: Adding current input to previous result
+ stored1 += firstNum
+ stored2 += secondNum
- fmt.Printf("=> %.1f %.1f\n", result1, result2)
+ fmt.Printf("=> %.1f %.1f\n", stored1, stored2)
}
}