I know what the boolean variables are: they are either true or false and are used to test a condition... but what I have issues with is the syntax... I do not know to include them properly into the structure of a .cpp file. Can anyone help me?... If possible, show me some source code in which they are used so I can get an idea of how to do it. Thanks in advance!
I need some help on how to work with boolean variables in C, and more particularly in Visual Studio .NET...?
With modern C++ compilers you do have the bool (note minuscules) type. You can declare it like this:
bool myBooleanVariable;
You may assign literals to it (literals for the bool data type are 'true' and 'false'):
myBooleanVariable = true;
myBooleanVariable = false;
You may assign them the result of boolean operations:
myBooleanVariable = (a %26gt; 5) %26amp;%26amp; (b %26lt; 2);
You may declare functions to return bool results:
bool IsInvoiceCurrent();
You may also test for their values directly:
if (myBooleanVariable) ...
if (!myBooleanVariable) ...
Reply::) It's good you know what they are... You can use boolean variables in Pascal, the type is boolean. But in C/C++ you don't have this type. So what you have to do is declare an integer variable, and you use it only with 2 values: 0 for false and 1 for true. that's what i do.
Reply:use this code to do it
public static void Main()
{
bool content = true;
bool noContent = false;
Console.WriteLine("It is {0} that C# Station provides C# programming language content.", content);
Console.WriteLine("The statement above is not {0}.", noContent);
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment