Added ability to input and store numbers
This commit is contained in:
parent
58aeefff0f
commit
e7f5cec04c
|
@ -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()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue