New newIncrement

Report a typo

Let's take a look once again at the newIncrement() function from theory:

func newIncrement() func() int {
    var number int
    return func() int {
        number += 1
        return number
    }
}

And create a new function! But you need to make two upgrades:

  • the newIncrement() function should take as an argument the start value of a number;
  • the newIncrement() function should increment the number variable by the value of inc.

Your program will take as input two numbers: a start value and an inc value. Finally, you need to print the result of increment.

Sample Input 1:

1 -1

Sample Output 1:

0
Write a program in Go
package main

import "fmt"

func main() {
var start, inc int
fmt.Scan(&start, &inc)

increment := newIncrement(?)
fmt.Println(increment(?))
}

func newIncrement(?) func(?) int {
number := ?
return func(? int) int {
number += ?
return number
}
}
___

Create a free account to access the full topic