golang-exercises/mclibre/media-aritmetica/main.go

37 lines
818 B
Go
Raw Normal View History

package main
import (
"bufio"
"fmt"
"os"
"strconv"
"strings"
)
func main() {
fmt.Println("CÁLCULO DE LA MEDIA DE DOS NÚMEROS")
reader := bufio.NewReader(os.Stdin)
fmt.Print("Escriba un número: ")
num1String, _ := reader.ReadString('\n')
fmt.Print("Escriba otro número: ")
num2String, _ := reader.ReadString('\n')
num1String = strings.TrimRight(num1String, "\n")
num2String = strings.TrimRight(num2String, "\n")
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("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
}