#Typing 5 for input but returning Failed why?
63 messages ยท Page 1 of 1 (latest)
add fmt.Printf("%q\n", answer) in CheckAnswer and see what is the output
Also the global here makes little sense, I guess you are begining that fine, just don't go think this is an acceptable usage of global variables ๐
(this is bad because if there are multiple pieces of code using this, they will colide on the global which is really confusing, you should lookup return)
so should i check answer inAskQuestion?
depends, there are multiple ways to do this
that would work
if you don't know about it, lookup return (really ๐)
I almost forgot i tried to check it on AskQuestion but i got failed again
I don't see fmt.Printf("%q\n", answer) anywhere here
and ? (you are almost there)
What \r\n is ?
Yeah np
so you look at your code, you have ReadString('\n')
you can also google "golang trailing \r\n" ๐
uh should i remove it when i get input everytime?
you trimmed the string \r\n
if you remove all whitespace from \r\n you indeed get nothing
what are you trying to do ? ๐
I don't belive so, if the user gives you 6, do you want to get 5 ?
then why are you not triming the input ?
hum hum ^^ ?
it's the input that you want to cleanup, not \r\n
we have all been there
i noticed it here i typed wrong everything there ๐
@split wren to recap.
ReadString('\n') is inclusive, it will give you all data until it find the thing you pass it in, right now you read until \n which is a magic character representing a new line.
5\r\n is really the key sequence 5 + ENTER (you have an extra \r too because you are on windows)
So what you did is passed your string into strings.TrimSpace which will remove all the whitespaces left and right of your data.
This includes the ENTER key.
Which leaves you with just 5 (or whatever was written in).
I totally understand
thank you so much
Also do i have anyway for convert string to int?
You really want to start checking for errors tho (no _ := ...).
@split wren you can also lookup fmt.Scan and fmt.Scanf
uh okay
also
i want to check it in CheckAnswer()
it is looking like that
now, the output of the fmt.Printf("%q\n", value) is "5\r\n"
all good
i typed that value = strings.TrimSpace("\r\n")
now it is ""