Minor tweaks

This commit is contained in:
raul 2024-03-20 20:59:48 +01:00
parent 6711bc5de5
commit 2a0ce3f89d
2 changed files with 28 additions and 12 deletions

View File

@ -8,6 +8,7 @@ import (
var numsToSum []int
var choice2 int
var isAveraged bool
func getAverage(arr []int, c chan int) {
sum := 0
@ -26,7 +27,11 @@ func statusMSG() {
fmt.Printf("Current numbers: %v\n", numsToSum)
fmt.Println("[1] Add number")
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() {
@ -65,12 +70,13 @@ looper:
// Send function call to goroutine while providing the channel for communication
go getAverage(numsToSum, c)
fmt.Printf("\rThinking.")
time.Sleep(time.Second)
fmt.Printf("\rThinking..")
time.Sleep(time.Second)
fmt.Printf("\rThinking...")
time.Sleep(time.Second)
// This is far better than repeating myself, I can even expand the amount of dots it'll use!
thinkstr := "Thinking"
for i := 0; i < 4; i++ {
fmt.Printf("\r%v", thinkstr)
time.Sleep(time.Second)
thinkstr = thinkstr + "."
}
fmt.Printf("\r\n")
// Get the result returned by the goroutine
@ -81,6 +87,10 @@ looper:
fmt.Printf("The average value is %v\n", average)
time.Sleep(time.Second * 3)
case 3:
fmt.Printf("\rThe array has been set to null")
numsToSum = nil
time.Sleep(time.Second)
case 4:
break looper
}
}

View File

@ -11,15 +11,19 @@ var check bool = false
var choice string
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() {
var numChoice int
for {
clear()
fmt.Printf("[1] Basic concurrency\n")
fmt.Printf("[2] Channels\n")
fmt.Printf("\rChoose your function: ")
mainStatus()
strChoice := scanLine()
numChoice, err = strconv.Atoi(strChoice)
@ -32,6 +36,8 @@ func main() {
case 2:
fun2()
os.Exit(0)
case 3:
os.Exit(0)
default:
fmt.Printf("Choose an actual function, please\n")
time.Sleep(time.Second)