I looked on this site and I searched it on google, but I can't find out how to actually use Boolean Operators. I know the symbols, such as ! means not, but I don't know how to make the function work. All I know is stuff like this: (3 != 2) // evaluates to true.
Can anyone tell me how or point me to a page that shows me how? I'm mostly just looking for a simple example, because I can easily see how to do it from examples. It can't be anything complex though, beyond a simple Boolean operator, because I'm not far in programming yet.
int a = 10;
int b = 21;
if(a == b)
{
cout << "Equal too.\n";
}
elseif(a > b)
{
cout << "A is greater than B\n";
}
elseif(a < b)
{
cout << "A is less than B\n";
}
elseif(a <= b)
{
cout << "A is less than or equal too B\n";
}
elseif(a >= b)
{
cout << "A is greater than or equal to B\n";
}
In this case it the program executes the less than loop (Note the >= and <= statements will never get executed)
In a for statement:
1 2 3 4
for(int i = 0; i <= 10; ++i)
{
cout << i << endl;
}
In the for loop i is initialized to 0 and then the loop is executed and i is incremented. Then if i is less than or equal too 10 the loop will execute again.