BOOLEAN is a binary type that returns 0 for FALSE, and anything else (typically 1) for TRUE. It is *not* a character-string. You *will* have to do some manipulation in order to associate the actual BOOLEAN values to text/string output.Originally posted by: ghidu
I want a boolean function to return true or false and not 1 or 0. I mean I'm printing the value and I want to look like "it's true" and not "it's 1". and I don't want to use IF in the main program.
Thanks
Maybe you can shed some light on this. The function is boolean and has to return "true" or "false"Originally posted by: cKGunslinger
BOOLEAN is a binary type that returns 0 for FALSE, and anything else (typically 1) for TRUE. It is *not* a character-string. You *will* have to do some manipulation in order to associate the actual BOOLEAN values to text/string output.Originally posted by: ghidu
I want a boolean function to return true or false and not 1 or 0. I mean I'm printing the value and I want to look like "it's true" and not "it's 1". and I don't want to use IF in the main program.
Thanks
Yes, "logical" TRUE and FALSE, not the actual ascii characters T-R-U-E.Originally posted by: ghidu
Maybe you can shed some light on this. The function is boolean and has to return "true" or "false"Originally posted by: cKGunslinger
BOOLEAN is a binary type that returns 0 for FALSE, and anything else (typically 1) for TRUE. It is *not* a character-string. You *will* have to do some manipulation in order to associate the actual BOOLEAN values to text/string output.Originally posted by: ghidu
I want a boolean function to return true or false and not 1 or 0. I mean I'm printing the value and I want to look like "it's true" and not "it's 1". and I don't want to use IF in the main program.
Thanks
Let's just say it checks if a number is even or odd.Originally posted by: xtknight
Can you tell us what you are trying to accomplish with this or give us some background on the program you want to make?
Blech, Poor Programming Pratice...
Originally posted by: xtknight
I don't think there's any printf parameter that will print out "true" when a 0 or 1 is specified.
The "true" or "TRUE" you type in your code is replaced by a 1 when the program is compiled. Likewise the "false" and "FALSE" are replaced by a 0. The program doesn't know the difference between FALSE and 0.
This is all you need to do.
if (num%2) // or if string ends with 0,2,4,6,8->even, string ends with 1,3,5,7,9->odd. may save processing for large integers.
printf("number is odd\n");
else
printf("number is even\n");
Originally posted by: ghidu
Originally posted by: xtknight
I don't think there's any printf parameter that will print out "true" when a 0 or 1 is specified.
The "true" or "TRUE" you type in your code is replaced by a 1 when the program is compiled. Likewise the "false" and "FALSE" are replaced by a 0. The program doesn't know the difference between FALSE and 0.
This is all you need to do.
if (num%2) // or if string ends with 0,2,4,6,8->even, string ends with 1,3,5,7,9->odd. may save processing for large integers.
printf("number is odd\n");
else
printf("number is even\n");
Thanks guys, but what I have to do is print "The number is even - " TRUE ;or FALSE; (return of the boolean function.
result = functionThatReturnsBoolean();
printf ("The number is even: ");
if (FALSE == result)
{
printf(" FALSE. \n");
}
else
{
printf(" TRUE. \n");
}
char textArray[2][10];
textArray[0] = "FALSE\0";
textArray[1] = "TRUE\0;
result = functionThatReturnsBoolean();
printf ("The number is even: %s.\n", textArray[result] );
printf parametersOriginally posted by: ghidu
Thanks guys, but what I have to do is print "The number is even - " TRUE ;or FALSE; (return of the boolean function.
EDIT: actually I think there is a parameter for printf, but I'm using cout and I don't remember what parameter, it's been a long time.
result = functionThatReturnsBoolean();
printf ("The number is even: ");
if (FALSE == result)
{
printf(" FALSE. \n");
}
else
{
printf(" TRUE. \n");
}
char textArray[2][10];
textArray[0] = "FALSE\0";
textArray[1] = "TRUE\0;
result = functionThatReturnsBoolean();
printf ("The number is even: %s.\n", textArray[result] );
Originally posted by: ghidu
What I asked is if there is a way to print the string TRUE insted of 1 from the value returned by the boolean function without an if/else because that I already knew how to do it and I didn't ask for help to modify the examples.
Originally posted by: itachi
it's best not to antagonize people who are trying to help you.
char *bstr [] = {"TRUE", "FALSE"};
...
int num;
...
printf ("The number if odd - %s", bstr[num & 1]);
printf ("The number is even - %s", bstr[(num + 1) & 1]);
Originally posted by: IHateMyJob2004
I read the thread.
THERE IS NO WAY TO PRINT "TRUE" OR "FALSE" IN C/C++ WITHOUT USING A CONDITIONAL OPERATION!
Sorry, but you seem to not be hearing what others have lready told you. Your only other option is to create a Boolean class and overload the operators in it to dispaly what you want.
c++ doesn't specify booleans as 1-bit values.. so '(int) check' could return 0xff for all you know, which would be sign-extended to -1.Originally posted by: TerryMathews
You could make a two-element array and typecast the bool into an int. Something like this:
bool check;
check = whatever();
string[2] validity {"True","False"};
cout << validity[(int)check];
Note this is not 100% compliant C++ code, you can do your own homework.
Originally posted by: itachi
c++ doesn't specify booleans as 1-bit values..