Help regarding code with channels in golang

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.

  1. Every 1 hour person is eligible for 5 min short break
  2. 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 (

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
			//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.Print("Enter your choice (C/E) ")
a := checkResponse()
fmt.Println(" Value of A is ", a)*/

var input string


Not able to print the same value that I enter from my console using scanf.

Is this the part where your problem occurs?

What do you enter at the console, what is the output that you expected, and what do you see insead?

And a general tip for troubleshooting: Always check the error values that a function returns. They provide helpful messages and also allow breaking the porgram early, to avcoid that it can go into an undefined state.

Scanf() returns the number of characters successfully read, and an error value. Capture both return values, and if the error value is not nil, print the error along with the successfully read characters. This will reveal where Scanf() fails.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.