Missing line

Report a typo

Edwin has created a Go program to test his knowledge about channels and tried to run it. However, during execution, his program ran into a fatal error!

The cause of the fatal error is that the sender function is missing an essential code line to send a flag that no more values will be transmitted on the channel.

Please help Edwin add the missing line in the sender function to fix his program.

Sample Input 1:

3

Sample Output 1:

done
done
done
Write a program in Go
package main

import (
"fmt"
"time"
)

// fix this function by adding the missing line
func sender(ch chan int, amount int) {
for i := 0; i < amount; i++ {
time.Sleep(200 * time.Millisecond)
ch <- 1
}
}

// do not change the code bellow
func main() {
var amount int
fmt.Scan(&amount)

ch := make(chan int)
go sender(ch, amount)

for range ch {
fmt.Println("done")
}
}
___

Create a free account to access the full topic