Create program using goroutines and gochannels for below situation:
Developer is working on assigment on his computer. Developer wants to work in the following fashion so as to work on deliverables and also take small breaks and long break.
- Every 1 hour person is eligible for 5 min short break
- After 3 hours , person is eligible for long break of 30 min. When timer hits long break, application should ask user if application continues or user wants to exit for the day (i.e. application closes)
To expedite execution of program, you can provide option to set time.
My code until now…
package main
import (
“fmt”
“time”
)
func main() {
c1 := make(chan string)
c2 := make(chan string)
go func() {
for {
time.Sleep(time.Second * 15)
c1 <- "eligible for a 5 minute break"
}
}()
go func() {
for {
time.Sleep(time.Second * 17)
c2 <- "eligible for a 30 minute break"
}
}()
go func() {
for {
select {
case msg2 := <-c2:
var i string
fmt.Println(msg2)
//i := "Yes"
fmt.Println("Enter a value ")
fmt.Scanf("%s", &i)
fmt.Println("Value taken ", i)
if i == "Yes" {
fmt.Println("Printing Yes ", i)
} else {
fmt.Println("Noooooooooo", i)
}
//var dump int
//fmt.Println("Enter 1 to Continue")
//fmt.Scanf("%s", &i)
//fmt.Printf("Value of dump is %s", i)
/*case msg1 := <-c1:
fmt.Println(msg1)*/
}
}
}()
/*fmt.Print("Enter your choice (C/E) ")
a := checkResponse()
fmt.Println(" Value of A is ", a)*/
var input string
fmt.Scanln(&input)
}
Not able to print the same value that I enter from my console using scanf.