Minor tweaks
This commit is contained in:
parent
6711bc5de5
commit
2a0ce3f89d
|
@ -8,6 +8,7 @@ import (
|
||||||
|
|
||||||
var numsToSum []int
|
var numsToSum []int
|
||||||
var choice2 int
|
var choice2 int
|
||||||
|
var isAveraged bool
|
||||||
|
|
||||||
func getAverage(arr []int, c chan int) {
|
func getAverage(arr []int, c chan int) {
|
||||||
sum := 0
|
sum := 0
|
||||||
|
@ -26,7 +27,11 @@ func statusMSG() {
|
||||||
fmt.Printf("Current numbers: %v\n", numsToSum)
|
fmt.Printf("Current numbers: %v\n", numsToSum)
|
||||||
fmt.Println("[1] Add number")
|
fmt.Println("[1] Add number")
|
||||||
fmt.Println("[2] Calculate average")
|
fmt.Println("[2] Calculate average")
|
||||||
fmt.Println("[3] Exit")
|
fmt.Println("[3] Flush array")
|
||||||
|
fmt.Println("[4] Exit")
|
||||||
|
if isAveraged == true {
|
||||||
|
fmt.Println()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func getChoice2() {
|
func getChoice2() {
|
||||||
|
@ -65,12 +70,13 @@ looper:
|
||||||
// Send function call to goroutine while providing the channel for communication
|
// Send function call to goroutine while providing the channel for communication
|
||||||
go getAverage(numsToSum, c)
|
go getAverage(numsToSum, c)
|
||||||
|
|
||||||
fmt.Printf("\rThinking.")
|
// This is far better than repeating myself, I can even expand the amount of dots it'll use!
|
||||||
time.Sleep(time.Second)
|
thinkstr := "Thinking"
|
||||||
fmt.Printf("\rThinking..")
|
for i := 0; i < 4; i++ {
|
||||||
time.Sleep(time.Second)
|
fmt.Printf("\r%v", thinkstr)
|
||||||
fmt.Printf("\rThinking...")
|
time.Sleep(time.Second)
|
||||||
time.Sleep(time.Second)
|
thinkstr = thinkstr + "."
|
||||||
|
}
|
||||||
fmt.Printf("\r\n")
|
fmt.Printf("\r\n")
|
||||||
|
|
||||||
// Get the result returned by the goroutine
|
// Get the result returned by the goroutine
|
||||||
|
@ -81,6 +87,10 @@ looper:
|
||||||
fmt.Printf("The average value is %v\n", average)
|
fmt.Printf("The average value is %v\n", average)
|
||||||
time.Sleep(time.Second * 3)
|
time.Sleep(time.Second * 3)
|
||||||
case 3:
|
case 3:
|
||||||
|
fmt.Printf("\rThe array has been set to null")
|
||||||
|
numsToSum = nil
|
||||||
|
time.Sleep(time.Second)
|
||||||
|
case 4:
|
||||||
break looper
|
break looper
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,15 +11,19 @@ var check bool = false
|
||||||
var choice string
|
var choice string
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
|
func mainStatus() {
|
||||||
|
clear()
|
||||||
|
fmt.Printf("[1] Basic concurrency\n")
|
||||||
|
fmt.Printf("[2] Channels\n")
|
||||||
|
fmt.Printf("[3] Exit\n")
|
||||||
|
fmt.Printf("\rChoose your function: ")
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
var numChoice int
|
var numChoice int
|
||||||
|
|
||||||
for {
|
for {
|
||||||
clear()
|
mainStatus()
|
||||||
fmt.Printf("[1] Basic concurrency\n")
|
|
||||||
fmt.Printf("[2] Channels\n")
|
|
||||||
|
|
||||||
fmt.Printf("\rChoose your function: ")
|
|
||||||
|
|
||||||
strChoice := scanLine()
|
strChoice := scanLine()
|
||||||
numChoice, err = strconv.Atoi(strChoice)
|
numChoice, err = strconv.Atoi(strChoice)
|
||||||
|
@ -32,6 +36,8 @@ func main() {
|
||||||
case 2:
|
case 2:
|
||||||
fun2()
|
fun2()
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
|
case 3:
|
||||||
|
os.Exit(0)
|
||||||
default:
|
default:
|
||||||
fmt.Printf("Choose an actual function, please\n")
|
fmt.Printf("Choose an actual function, please\n")
|
||||||
time.Sleep(time.Second)
|
time.Sleep(time.Second)
|
||||||
|
|
Loading…
Reference in New Issue