2024-01-30 06:47:29 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2024-01-30 09:42:16 +01:00
|
|
|
"os"
|
|
|
|
//"log"
|
2024-01-30 06:47:29 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
// https://golangr.com/range
|
|
|
|
// TODO: Create something similar to the array exercise but cleaner and better
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
func main() {
|
2024-01-30 09:42:16 +01:00
|
|
|
start()
|
|
|
|
}
|
|
|
|
|
|
|
|
func start() {
|
2024-01-30 06:47:29 +01:00
|
|
|
fmt.Print("\033[H\033[2J")
|
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")
|
|
|
|
println("[4] Get min and max grade")
|
|
|
|
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: ")
|
|
|
|
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) {
|
|
|
|
|
2024-01-30 06:47:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func average() {
|
2024-01-30 09:42:16 +01:00
|
|
|
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) {
|
2024-01-30 06:47:29 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2024-01-30 09:42:16 +01:00
|
|
|
func max(num float64) {
|
2024-01-30 06:47:29 +01:00
|
|
|
|
|
|
|
}
|
2024-01-30 09:42:16 +01:00
|
|
|
|
|
|
|
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()
|
|
|
|
}
|