0

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!

4
Contributors
9
Replies
10
Views
7 Years
Discussion Span
Last Post by jonsca
1

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.

Votes + Comments
Yeah, very helpful
0

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.

0

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.

0

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.

0

I believe it said something like incorrect use of std::string or something of that sort.

0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.