Useful defer statement

Report a typo

Below is a Go program that takes as an input three int values; these values are further read in the hidden function hiddenValuesHandler() and returned as a result.

Your task is to use the defer statement with an anonymous function to check the three resulting values following these rules:

  • The value of the variable num1 must be in the range from 0 to 100 ([0, 100]);
  • The value of the variable num2 must be a positive number (num2 > 0);
  • The value of the variable num3 must be an even number.

Finally, depending on the result of checking each variable, your program should print OK or ERROR.

Sample Input 1:

1 2 3

Sample Output 1:

num1: OK
num2: OK
num3: ERROR
Write a program in Go
package main

import "fmt"

func main() {
var num1, num2, num3 int32

defer ?

// Do not remove the line below!
num1, num2, num3 = hiddenValuesHandler()
}
___

Create a free account to access the full topic