Completed exercise and added min-max-array library

I'm done with this for now, gonna move on to newer projects instead of
getting stuck here
This commit is contained in:
raul 2024-01-31 07:19:14 +00:00
parent 20a539b9c4
commit fde585b7ad
3 changed files with 31 additions and 19 deletions

View File

@ -1,3 +1,5 @@
module range module range
go 1.21.6 go 1.21.6
require git.bulgariu.xyz/raul/min-max-array v0.0.0-20240130184833-a25a49c11fc5

2
golangr/range/go.sum Normal file
View File

@ -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=

View File

@ -2,6 +2,7 @@ package main
import ( import (
"fmt" "fmt"
"git.bulgariu.xyz/raul/min-max-array"
"os" "os"
//"log" //"log"
) )
@ -40,7 +41,10 @@ func msg() {
func choices() { func choices() {
for { for {
fmt.Printf("Choice: ") fmt.Printf("Choice: ")
fmt.Scan(&choice) _, err := fmt.Scan(&choice)
if err != nil {
fmt.Println(err)
}
switch choice { switch choice {
case 1: case 1:
addVec() addVec()
@ -49,22 +53,22 @@ func choices() {
case 3: case 3:
average() average()
case 4: case 4:
getMinMax()
case 5: case 5:
resetGrades() resetGrades()
case 6: case 6:
fmt.Println("Have a nice day") fmt.Println("Have a nice day!")
os.Exit(0) os.Exit(0)
default: default:
clear()
msg() 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() { func average() {
clear() clear()
msg() msg()
@ -75,16 +79,24 @@ func average() {
notaMedia := notaSumada / float64(len(notas)) notaMedia := notaSumada / float64(len(notas))
fmt.Printf("\n-----------------------------------------------") fmt.Printf("\n-----------------------------------------------")
fmt.Printf("\nAll your grades combine to %v\n", notaSumada) fmt.Printf("\nAll your grades combine to %.2v\n", notaSumada)
fmt.Printf("Your average grade is %v\n", notaMedia) fmt.Printf("Your average grade is %.2v\n", notaMedia)
fmt.Printf("-----------------------------------------------\n\n") fmt.Printf("-----------------------------------------------\n\n")
notaSumada = 0 notaSumada = 0
notaMedia = 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() { func resetGrades() {
@ -100,14 +112,10 @@ func addVec() {
clear() clear()
fmt.Println("Add a number to your vector") fmt.Println("Add a number to your vector")
fmt.Printf("Number: ") fmt.Printf("Number: ")
fmt.Scanln(&numToAdd) _, err := fmt.Scanln(&numToAdd)
if err != nil {
// TODO: get error handling going after initial functionality is done fmt.Println(err)
// if len(numToAdd) == 0 { }
//
// } else {
//
// }
notas = append(notas, numToAdd) notas = append(notas, numToAdd)
clear() clear()