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