+ 1
You are building a Timer app that should count up to a given number. Your program needs to take a number as input and make the
Variable is not increament package main import "fmt" type Timer struct { id string value int } func (t Timer)tick (){ fmt.Println(t.value +1) t.value+=1 } func main() { var x int fmt.Scanln(&x) t := Timer{"timer1", 0} for i:=0;i<x;i++ { t.tick() } }
2 Answers
+ 7
func (t *Timer) tick () {
t.value++
fmt.Println(t.value)
}
+ 1
You are building a Timer app that should count up to a given number Your program needs to take a number as input and make the Timer tick that number of times.
The code in main initializes a Timer and takes a number as input Then it calls the tick() method for the Timer the given number of D
times Define the Timer struct with two fields id and value, and define the tick() method, which should increment the value by one and output
its current value