Boolean Array

Hi guys: Can any one please tell me if this is the right way to create a boolean array in C++ ? Thanks.


mustish1Asked:
Who is Participating?
 
phoffricCommented:
'True' is not valid. A tick (') can used for a single char literal. Replacing with "True" does provide a character literal, but that is not valid when assigning to a bool type. This is valid:
answers[0][0] = true;

Open in new window

When initializing all the bools to true, I would use two for-loops. When printing out the values, I would replace the do-while and while-loops with two for-loops.
0
 
phoffricCommented:
I don't see the code.
0
 
mustish1Author Commented:
it just keep giving me this error when i try to post the code

All tags must have a closing tag.

there is no itag in the code
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
phoffricCommented:
If you have, for example, bracket i bracket, then that is a symbol for italics. Put the code in a code block.
0
 
mustish1Author Commented:
#include <iostream>
using namespace test;

int main()
{

	bool answers[3] [5] = {};
	int i = 0,   j = 000;
	answers[0][0] = 'True';
	answers[0][1] = 'True';
	answers[0][2] = 'True';
	answers[0][3] = 'True';
	answers[0][4] = 'True';

	answers[1][0] = 'True';
	answers[1][1] = 'True';
	answers[1][2] = 'True';
	answers[1][3] = 'True';
	answers[1][4] = 'True';

	answers[2][0] = 'True';
	answers[2][1] = 'True';
	answers[2][2] = 'True';
	answers[2][3] = 'True';
	answers[2][4] = 'True';
	do
    {  
        while(i < 3)  
        {  
            cout << answers[i][j] << endl;
			i++;
        }
		i = 0;
		j++;
        cout << endl;
    }	while(j < 5);

	system("pause");
	return 0;
}

Open in new window

error.txt
0
 
mustish1Author Commented:
It works. Thanks.
0
 
phoffricCommented:
You're welcome.  I meant to say:
Replacing with "True" does provide a character literal string, but ...
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.