Post
avtar img holder

Yonseo

2019-09-04 07:49:06

Booleans & Truth Tables

avtar img holder

The logic behind booleans is either true or false, 1 or 0. A statements is made and tested for a binary result.

If the statement is true then execute code. In this statement I want to know if sushi is true.

#include
using namespace std;

int main()
{
    bool sushi = true;
    bool ramen = false;

    if(sushi)
    {
        cout << "sushi is TRUE" << "\n";
    }
    return 0;
}


If NOT sushi and ramen is false then execute code. In this statement sushi is true so NOT sushi is false. If the statement is found to be true then proceed with code execution. 

#include
using namespace std;

int main()
{
    bool sushi = true;
    bool ramen = false;

    if((!sushi && ramen) == false)
    {
        cout << "sushi and ramen are both FALSE" << "\n";
    }
    return 0;
}

OR

In boolean 1 = TRUE and 0 = FALSE. By using boolean logic the OR operator written as + we can see that 1 + 1 = 1 and 1 + 0 = 1  and 0 + 0 = 0. Only one must be found to be true to make it a true statement.

#include
using namespace std;

int main()
{
    bool sushi = true;
    bool ramen = false;

    if(sushi || ramen)
    {
    cout << "sushi is TRUE";
    }
    return 0;
}

Think of the operator OR as an alarm that can only be on or off. Then we can see that having one alarm ON will make a sound regardless if the other alarm is on or off.

AND

When using the AND operator written as * both must be true to equal true otherwise it will default to false.

#include
using namespace std;

int main()
{
    bool sushi = true;
    bool ramen = false;

    if(sushi && !ramen)
    {
        cout << "sushi and ramen are TRUE";
    }
    return 0;
}

Latest Posts

avtar img holder
React JS Study Notes
Category
avtar img holder
Creating a Component in React JS
Category
avtar img holder
Javascript for Bubble Tea
Category
avtar img holder
Github Commands
Category
avtar img holder
FuelPHP Login & Authentication
Category
avtar img holder
Intro to C++
Category

COPYRIGHT © 2019Taiyaki.io All rights ReservedHand-crafted & Made with