Properly finished arithmetic average exercise

I've never done something so convoluted in my life, I think I should
just stick to fmt.scan whenever I'm asking for simple inputs
This commit is contained in:
raul 2024-01-25 19:50:52 +01:00
parent 09ecc6a483
commit dd1849da8e
2 changed files with 16 additions and 12 deletions

View File

@ -0,0 +1,3 @@
module media-aritmetica
go 1.21.6

View File

@ -4,7 +4,8 @@ import (
"bufio" "bufio"
"fmt" "fmt"
"os" "os"
//"strconv" "strconv"
"strings"
) )
func main() { func main() {
@ -16,20 +17,20 @@ func main() {
fmt.Print("Escriba otro número: ") fmt.Print("Escriba otro número: ")
num2String, _ := reader.ReadString('\n') num2String, _ := reader.ReadString('\n')
// num1, err := strconv.Atoi(num1String) num1String = strings.TrimRight(num1String, "\n")
// if err != nil { num2String = strings.TrimRight(num2String, "\n")
// panic(err)
// }
// num2, err := strconv.Atoi(num2String)
// if err != nil {
// panic(err)
// }
fmt.Printf("%v y %v", num1String, num2String) num1, err := strconv.Atoi(num1String)
if err != nil {
panic("Please type an actual number")
}
num2, err := strconv.Atoi(num2String)
if err != nil {
panic("Please type an actual number")
}
// fmt.Printf("Has escrito %v y %v\n", num1String, num2String) fmt.Printf("La media aritmética de %v y %v es %v\n", num1, num2, (num1+num2)/2)
// This is so incredibly convoluted I'm having a stroke // This is so incredibly convoluted I'm having a stroke
// TODO: make this less painful to look at // TODO: make this less painful to look at
} }