Hello, I need help with this problem I came across. What I have is this:

char answers[5][4] = {{'1','2','3','4'},{'10','0','3','0'},{'1','0','0','0'},{'1','2','3','4'},{'1','0','0','4'}};

However, this code does not accept 2 digits..only one. This irks me, and I was wondering if there was a way to add 2 digits.

Note: I am going to convert this to characters, so declaring as int won't work!

I would add another dimension to your array, e.g.:

char answers2[5][4][2] = {{{'1','2'},{'1','2'},{'1','2'},{'1','2'}},{{'1','2'},{'1','2'},{'1','2'},{'1','2'}},{{'1','2'},{'1','2'},{'1','2'},{'1','2'}},{{'1','2'},{'1','2'},{'1','2'},{'1','2'}},{{'1','2'},{'1','2'},{'1','2'},{'1','2'}}};

(has all 12s but you get the idea)
or you could use an array of strings to accomplish the same thing (leave it as 2D).
You have a '10' in your array which isn't a char.

Comments
Yeah, very helpful

I would add another dimension to your array, e.g.:

char answers2[5][4][2] = {{{'1','2'},{'1','2'},{'1','2'},{'1','2'}},{{'1','2'},{'1','2'},{'1','2'},{'1','2'}},{{'1','2'},{'1','2'},{'1','2'},{'1','2'}},{{'1','2'},{'1','2'},{'1','2'},{'1','2'}},{{'1','2'},{'1','2'},{'1','2'},{'1','2'}}};

(has all 12s but you get the idea)
or you could use an array of strings to accomplish the same thing (leave it as 2D).
You have a '10' in your array which isn't a char.

Thanks, this helps. Could you give me a string example? I tried it with string but gave me a bunch of errors.

Something like this: std::string answers[3][2] = {{"12","12"}, {"12","12"},{"12","12"}};

Heh..I did about the same thing before, but it didn't work. Must have been an error that I didn't see.

This however does work. Thanks.

Heh..I did about the same thing before, but it didn't work. Must have been an error that I didn't see.

This however does work. Thanks.

No prob. Do you remember what kind of errors it was giving you? Sometimes you miss one brace or something....it ends up befuddling everything.

You could have left a " off somewhere. I got a similar error to yours when I did that. Honestly I'm not sure...

This article has been dead for over six months. Start a new discussion instead.