golang-exercises/golangr/array/main.go

80 lines
1.3 KiB
Go

package main
import (
"fmt"
"os"
"time"
//"log"
)
var notas []float64
var num float64
var choice int
func main() {
fmt.Print("\033[H\033[2J")
fmt.Printf("Welcome to the vector playground\n\n")
msg()
options()
}
func options() {
for {
fmt.Scanln(&choice)
switch choice {
case 1:
addVec()
case 2:
showResults()
case 3:
fmt.Println("Have a nice day!")
os.Exit(0)
default:
fmt.Print("\033[H\033[2J")
fmt.Printf("[-] ERROR: invalid input\n\n")
fmt.Printf("[1] Add to vector\n")
fmt.Printf("[2] View results\n")
fmt.Printf("[3] Exit\n")
fmt.Printf("\nPlease, select your choice: ")
}
}
}
func msg() {
fmt.Print("\033[H\033[2J")
fmt.Printf("[1] Add to vector\n")
fmt.Printf("[2] View results\n")
fmt.Printf("[3] Exit\n")
fmt.Printf("\nPlease, select your choice: ")
}
func addVec() {
fmt.Print("\033[H\033[2J")
fmt.Printf("Which number would you like to add to the vector?\nNumber: ")
fmt.Scanln(&num)
if num >= 0.001 && num <= 10 {
} else {
msg()
fmt.Println("\nERROR: Invalid number")
return
}
notas = append(notas, num)
//time.Sleep(2 * time.Second)
fmt.Printf("You have added the number %v!", num)
time.Sleep(2 * time.Second)
msg()
}
func showResults() {
fmt.Printf("These are your current grades: \n")
fmt.Print(notas)
time.Sleep(2 * time.Second)
msg()
}