package main
import (
"fmt"
"math/rand"
)
// x = 40
func main() {
x := 4
if z := 5 * rand.Intn(x); z >= x {
fmt.Printf("z is greater than x")
}
the above code is not working but the below code is working:
package main
import (
"fmt"
"math/rand"
)
// x = 40
func main() {
x := 4
if z := 5 * rand.Intn(x); z >= x {
fmt.Printf("z is greater than x")
} else {
fmt.Printf("z is smaller than x")
}
}
Hello, @GauravJiSri, and welcome to the Go community!
Is there a closing } missing from your first example?
EDIT:
With an added } for ending the if block, this will compile and execute:
package main
import (
"fmt"
"math/rand"
)
// x = 40
func main() {
x := 4
if z := 5 * rand.Intn(x); z >= x {
fmt.Printf("z is greater than x")
} // end if
} // end main
Depending upon the randomized value assigned to z, this will sometimes be output: