package main import ( "fmt" "git.bulgariu.xyz/raul/min-max-array" "os" //"log" ) // https://golangr.com/range var notas []float64 var choice int8 var numToAdd float64 var notaSumada float64 func clear() { fmt.Print("\033[H\033[2J") } func main() { start() } func start() { clear() msg() choices() } func msg() { println("[1] Add grade to vector") println("[2] View grades") println("[3] Get grade average") println("[4] Get min / max grade") println("[5] Reset grades") println("[6] Exit") } func choices() { for { fmt.Printf("Choice: ") _, err := fmt.Scan(&choice) if err != nil { fmt.Println(err) } switch choice { case 1: addVec() case 2: viewGrades() case 3: average() case 4: getMinMax() case 5: resetGrades() case 6: fmt.Println("Have a nice day!") os.Exit(0) default: clear() msg() fmt.Printf("\n-----------------------------------------------\n") fmt.Printf("ERROR: Invalid input\n") fmt.Printf("-----------------------------------------------\n\n") } } } func average() { clear() msg() for _, elem := range notas { notaSumada = notaSumada + elem } notaMedia := notaSumada / float64(len(notas)) fmt.Printf("\n-----------------------------------------------") fmt.Printf("\nAll your grades combine to %.2v\n", notaSumada) fmt.Printf("Your average grade is %.2v\n", notaMedia) fmt.Printf("-----------------------------------------------\n\n") notaSumada = 0 notaMedia = 0 } func getMinMax() { clear() msg() // Me finally getting to make use of my first library :) minNota := minmax.Min(notas) maxNota := minmax.Max(notas) // minNota := Min(notas) // maxNota := Max(notas) fmt.Printf("\n-----------------------------------------------") fmt.Printf("\nLargest grade: %v\n", maxNota) fmt.Printf("Smallest grade: %v\n", minNota) fmt.Printf("-----------------------------------------------\n\n") } func resetGrades() { clear() msg() fmt.Printf("\n-----------------------------------------------") fmt.Printf("\nYour grades have been reset!\n") fmt.Printf("-----------------------------------------------\n\n") notas = nil } func addVec() { clear() fmt.Println("Add a number to your vector") fmt.Printf("Number: ") _, err := fmt.Scanln(&numToAdd) if err != nil { fmt.Println(err) } notas = append(notas, numToAdd) clear() msg() fmt.Printf("\n-----------------------------------------------") fmt.Printf("\nYou have added the number %v\n", numToAdd) fmt.Printf("-----------------------------------------------\n\n") numToAdd = 0 } func viewGrades() { clear() msg() fmt.Printf("\n-----------------------------------------------\n") fmt.Printf("These are your grades:") fmt.Printf("\n-----------------------------------------------\n") for _, elem := range notas { fmt.Println(elem) } fmt.Printf("-----------------------------------------------\n\n") }