Next level of taking input

hey y’all I know I’m probably not asking the right questions as I search google so I need some human help. I’m trying to create a struct then assign a value to a var in the struct from the main. So I’ll pose a question then assign the response the appropriate var in the struct. What is that called? Seems like it’s a slice but I can’t find anything quite like it while I’m clicking around.

Here is a playground version of what I’m trying to do.

cat in your code is a struct not an actual instance, modify your code to, hope it helps.

worked like a champ! So you have to st the struct as an instance? Ok what does Ins do exactly?

oh and thanks


type cat struct{
	color string
	name string

is a type definition, it only tells the compiler what a cat struct consists of. It is not itself a cat object. In manxiaqu’s code the catIns is just the name of the variable that was chosen to be an instance of the cat type you defined. Thus the Ins part of the variable name just stands for Instance, but you could have named the variable pretty much anything.

so here is the problem. It won’t assign the string more than once. I did exactly like y’all showed me and it did work on the one but not on the second one. Was wondering why? The playground link is here. it will show you what I mean. I wanted it to save the values and print them out at the end.

I’m not exactly understand “work on the one but not the second one”, What’s the second one. do you mean a loop or something?

It is not assigning the string to the variable in the struct. At least not the second one.

I run your code locally, and here’s the result.

what i see is that the input ‘a’ and ‘b’ have been assigned to c ins. what’s you excepted result if


mine does not. Hmmm, I’m using vscode as my editor and running it in the terminal. It takes the first input but skips taking the second one. wonder why? Glad it works for you. Wish it did for me.

it’s weird. the code is very simple and should work normal at different version or os. Any error message or logs(your terminal inputs/outpus) you can supply.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.