second version, again with gpt4 help

This commit is contained in:
NunoSempere 2024-05-10 19:07:36 +01:00
parent c7298061fa
commit a2648c8b95

26
main.go
View File

@ -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)
}
}