diff --git a/golangr/range/go.mod b/golangr/range/go.mod index 3b0f1c2..ff2ac0c 100644 --- a/golangr/range/go.mod +++ b/golangr/range/go.mod @@ -1,3 +1,5 @@ module range go 1.21.6 + +require git.bulgariu.xyz/raul/min-max-array v0.0.0-20240130184833-a25a49c11fc5 diff --git a/golangr/range/go.sum b/golangr/range/go.sum new file mode 100644 index 0000000..22a3196 --- /dev/null +++ b/golangr/range/go.sum @@ -0,0 +1,2 @@ +git.bulgariu.xyz/raul/min-max-array v0.0.0-20240130184833-a25a49c11fc5 h1:+4SdxwW8y687yR/ctDOdmcuJGxcI0oLPiNOrg28zSIo= +git.bulgariu.xyz/raul/min-max-array v0.0.0-20240130184833-a25a49c11fc5/go.mod h1:PdMyknNgNZYKg03bYhSc4aaSA/P3yScGPfxC4z+ju0c= diff --git a/golangr/range/main.go b/golangr/range/main.go index 17b895a..e4f8425 100644 --- a/golangr/range/main.go +++ b/golangr/range/main.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "git.bulgariu.xyz/raul/min-max-array" "os" //"log" ) @@ -40,7 +41,10 @@ func msg() { func choices() { for { fmt.Printf("Choice: ") - fmt.Scan(&choice) + _, err := fmt.Scan(&choice) + if err != nil { + fmt.Println(err) + } switch choice { case 1: addVec() @@ -49,22 +53,22 @@ func choices() { case 3: average() case 4: + getMinMax() case 5: resetGrades() case 6: - fmt.Println("Have a nice day") + fmt.Println("Have a nice day!") os.Exit(0) default: + clear() msg() - fmt.Println("Another one") + fmt.Printf("\n-----------------------------------------------\n") + fmt.Printf("ERROR: Invalid input\n") + fmt.Printf("-----------------------------------------------\n\n") } } } -func total(num float64) { - -} - func average() { clear() msg() @@ -75,16 +79,24 @@ func average() { 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("\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 minmax() { - +func getMinMax() { + clear() + msg() + // Me finally getting to make use of my first library :) + minNota := minmax.Min(notas) + maxNota := minmax.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() { @@ -100,14 +112,10 @@ 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 { - // - // } + _, err := fmt.Scanln(&numToAdd) + if err != nil { + fmt.Println(err) + } notas = append(notas, numToAdd) clear()