Added ability to input and store numbers

This commit is contained in:
raul 2024-01-28 07:41:55 +01:00
parent 58aeefff0f
commit e7f5cec04c
1 changed files with 36 additions and 14 deletions

View File

@ -2,38 +2,41 @@ package main
import (
"fmt"
"os"
"time"
//"log"
)
var notas []int
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")
//fmt.Printf("Welcome to this weird exercise\n\n")
fmt.Printf("[1] Add to vector\n")
fmt.Printf("[2] View results\n")
fmt.Printf("\nPlease, select your choice: ")
msg()
options()
}
var choice int
ask:
func options() {
for {
fmt.Scan(&choice)
fmt.Scanln(&choice)
switch choice {
case 1:
addVec()
break ask
case 2:
showResults()
break ask
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: ")
}
}
@ -41,17 +44,36 @@ ask:
}
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.Println("This is the vector add function!")
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.Println("This is the show results function!")
fmt.Printf("These are your current grades: \n")
fmt.Print(notas)
time.Sleep(2 * time.Second)
msg()
}