package main import ( "fmt" "os" //"log" ) // https://golangr.com/range // TODO: Create something similar to the array exercise but cleaner and better 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: ") fmt.Scan(&choice) switch choice { case 1: addVec() case 2: viewGrades() case 3: average() case 4: case 5: resetGrades() case 6: fmt.Println("Have a nice day") os.Exit(0) default: msg() fmt.Println("Another one") } } } func total(num float64) { } 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 %v\n", notaSumada) fmt.Printf("Your average grade is %v\n", notaMedia) fmt.Printf("-----------------------------------------------\n\n") notaSumada = 0 notaMedia = 0 } func minmax() { } 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: ") fmt.Scanln(&numToAdd) // TODO: get error handling going after initial functionality is done // if len(numToAdd) == 0 { // // } else { // // } 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") }