Scanner problem


My program can not get a value of “floatvalue” from scan function.
I am pretty sure that my code is coorect but for some reason it doesn’t execute right
Am i doing smth wrong?
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Visual Studio Code

Version: 1.48.1 (user setup)

Commit: 3dd905126b34dcd4de81fa624eb3a8cbe7485f13

Date: 2020-08-19T17:12:13.244Z

Electron: 7.3.2

Chrome: 78.0.3904.130

Node.js: 12.8.1

V8: 7.8.279.23-electron.0

OS: Windows_NT x64 10.0.18362

Name: Go

Id: golang.go

Description: Rich Go language support for Visual Studio Code

Version: 0.16.

Have you checked the return value of fmt.Scan?

That would have been much more important than your version of chrome, electron or vscode…

Also perhaps post code as text in a code block rather than a picture of the code.

1 Like

sry im such a nweby, how do u do this?

How do you do what?

Checking return values?

Copy pasting code instead of putting screenshots?

Describing problems instead of just dropping a picture saying nothing?

1 Like

how do u check return values

fmt.Scan returns 2 values.

The first is the number of items it successfully parsed, the second is an error value.

If the first value is less than the number of arguments you passed to fmt.Scan then something went wrong and the other return value will be non-nil. In practice most just check the error value instead of the number of parsed arguments, but print/log the number for debugging purposes.

_, err := fmt.Scan(&floatvalue)
if err != nil {
  panic(err)
}

ty

So if you add checking the error, how does that change the behaviour/output of the program?

It’s still the same, i allready found an error, so dont eorry about this and ty