diff --git a/mclibre/media-aritmetica/go.mod b/mclibre/media-aritmetica/go.mod new file mode 100644 index 0000000..28cc9ef --- /dev/null +++ b/mclibre/media-aritmetica/go.mod @@ -0,0 +1,3 @@ +module media-aritmetica + +go 1.21.6 diff --git a/mclibre/media-aritmetica/main.go b/mclibre/media-aritmetica/main.go index d2e9b39..e9c781d 100644 --- a/mclibre/media-aritmetica/main.go +++ b/mclibre/media-aritmetica/main.go @@ -4,7 +4,8 @@ import ( "bufio" "fmt" "os" - //"strconv" + "strconv" + "strings" ) func main() { @@ -16,20 +17,20 @@ func main() { fmt.Print("Escriba otro número: ") num2String, _ := reader.ReadString('\n') - // num1, err := strconv.Atoi(num1String) - // if err != nil { - // panic(err) - // } - // num2, err := strconv.Atoi(num2String) - // if err != nil { - // panic(err) - // } + num1String = strings.TrimRight(num1String, "\n") + num2String = strings.TrimRight(num2String, "\n") - 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 // TODO: make this less painful to look at - }