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!

hi,

Why do you need to convert it to characters?

Please be more specific.

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.

commented: Yeah, very helpful +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.

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"}};

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.

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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.