Why my code give me the wrong answer

package main

import (
“fmt”
)

func main() {
fmt.Println(" There is a sign at the entrance that says ‘Adults Only.’ ")
var age = 41
var minor = age < 18
fmt.Printf(“Am I an adult at %v? %v\n”, age, minor)
}
output:
There is a sign at the entrance that says ‘Adults Only’.
Am I an adult at 41? false

Hi! Why should be wrong? Is correct :slight_smile:

because in book says output that should be true
soo that book is wrong? that what i think

is listning on official page
image

ok i found the problem that is wrong translate to polish language

original code
package main

import “fmt”

func main() {
fmt.Println(“There is a sign near the entrance that reads ‘No Minors’.”)

var age = 41
var minor = age < 18

fmt.Printf("At age %v, am I a minor? %v\n", age, minor)

}
thx for help

1 Like

Good. You solved that problem by yourself.
May I know that book name?

Your code seems fine, but it appears that you might be using incorrect quotation marks around the import statement. In Go, you should use double quotation marks (") instead of the smart quotes (“ ”). Here’s the corrected version of your code:

goCopy code

package main

import (
	"fmt"
)

func main() {
	fmt.Println("There is a sign at the entrance that says 'Adults Only.'")
	var age = 41
	var minor = age < 18
	fmt.Printf("Am I an adult at %v? %v\n", age, !minor)
}

This should give you the expected output:

csharpCopy code

There is a sign at the entrance that says 'Adults Only.'
Am I an adult at 41? true

Note that I also added an exclamation mark (!) before the minor variable in the fmt.Printf() call to correctly print whether you are an adult or not based on the age and minor variables.

I always define the variable either via ‘var minor bool’ format or as ‘minor := age < 18’.