Added ability to input and store numbers
This commit is contained in:
parent
58aeefff0f
commit
e7f5cec04c
|
@ -2,38 +2,41 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"time"
|
||||||
//"log"
|
//"log"
|
||||||
)
|
)
|
||||||
|
|
||||||
var notas []int
|
var notas []float64
|
||||||
|
var num float64
|
||||||
|
var choice int
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
fmt.Print("\033[H\033[2J")
|
fmt.Print("\033[H\033[2J")
|
||||||
fmt.Printf("Welcome to the vector playground\n\n")
|
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
|
func options() {
|
||||||
|
|
||||||
ask:
|
|
||||||
for {
|
for {
|
||||||
fmt.Scan(&choice)
|
fmt.Scanln(&choice)
|
||||||
|
|
||||||
switch choice {
|
switch choice {
|
||||||
case 1:
|
case 1:
|
||||||
addVec()
|
addVec()
|
||||||
break ask
|
|
||||||
case 2:
|
case 2:
|
||||||
showResults()
|
showResults()
|
||||||
break ask
|
case 3:
|
||||||
|
fmt.Println("Have a nice day!")
|
||||||
|
os.Exit(0)
|
||||||
default:
|
default:
|
||||||
fmt.Print("\033[H\033[2J")
|
fmt.Print("\033[H\033[2J")
|
||||||
fmt.Printf("[-] ERROR: invalid input\n\n")
|
fmt.Printf("[-] ERROR: invalid input\n\n")
|
||||||
fmt.Printf("[1] Add to vector\n")
|
fmt.Printf("[1] Add to vector\n")
|
||||||
fmt.Printf("[2] View results\n")
|
fmt.Printf("[2] View results\n")
|
||||||
|
fmt.Printf("[3] Exit\n")
|
||||||
fmt.Printf("\nPlease, select your choice: ")
|
fmt.Printf("\nPlease, select your choice: ")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,17 +44,36 @@ ask:
|
||||||
}
|
}
|
||||||
|
|
||||||
func msg() {
|
func msg() {
|
||||||
|
fmt.Print("\033[H\033[2J")
|
||||||
fmt.Printf("[1] Add to vector\n")
|
fmt.Printf("[1] Add to vector\n")
|
||||||
fmt.Printf("[2] View results\n")
|
fmt.Printf("[2] View results\n")
|
||||||
|
fmt.Printf("[3] Exit\n")
|
||||||
|
|
||||||
fmt.Printf("\nPlease, select your choice: ")
|
fmt.Printf("\nPlease, select your choice: ")
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func addVec() {
|
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() {
|
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