diff --git a/golangr/range/main.go b/golangr/range/main.go index 2b85db4..377bbad 100644 --- a/golangr/range/main.go +++ b/golangr/range/main.go @@ -2,31 +2,112 @@ 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 main() { + start() +} + +func start() { fmt.Print("\033[H\033[2J") - fmt.Println("Welcome") + msg() + choices() } func msg() { - fmt.Print("\033[H\033[2J") - println() + println("[1] Add grade to vector") + println("[2] View grades") + println("[3] Get grade average") + println("[4] Get min and max grade") + println("[5] Reset grades") + println("[6] Exit") } func choices() { - fmt.Print("\033[H\033[2J") + for { + fmt.Printf("Choice: ") + fmt.Scanln(&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() { + fmt.Print("\033[H\033[2J") + msg() + + for _, elem := range notas { + notaSumada = notaSumada + elem + } + + notaMedia := notaSumada / float64(len(notas)) + fmt.Printf("\nAll your grades combine to %v\n", notaSumada) + fmt.Printf("Your average grade is %v\n\n", notaMedia) +} + +func min(num float64) { } -func minmax() { +func max(num float64) { } + +func resetGrades() { + fmt.Print("\033[H\033[2J") + msg() + fmt.Printf("\nYour grades have been reset!\n\n") + notas = nil +} + +func addVec() { + fmt.Print("\033[H\033[2J") + fmt.Println("Add a number to your vector") + fmt.Printf("Number: ") + fmt.Scanln(&numToAdd) + notas = append(notas, numToAdd) + fmt.Print("\033[H\033[2J") + msg() + fmt.Printf("\nYou have added the number %v\n\n", numToAdd) + + numToAdd = 0 +} + +func viewGrades() { + fmt.Print("\033[H\033[2J") + msg() + fmt.Println("\nThese are your grades:") + for _, elem := range notas { + fmt.Println(elem) + } + fmt.Println() +}