# Conditions » Examples

This example was developed throughout the entire Conditions lesson.

``#include <iostream>int main() {    std::cout << "Welcome to the Driver's License Oracle 5500\n";    int yearOfBirth;    std::cout << "Please enter your year of birth: ";    std::cin >> yearOfBirth;    int numCrashes;    std::cout << "Please enter the number of crashes you have had: \n";    std::cin >> numCrashes;    char licenseClass = 'X'; // X is chosen as a default value to signal if we miss one of our cases    std::string illegalReason;    if (numCrashes < 2) {        // Year 2022 at the moment of writing this lesson        int age = 2022 - yearOfBirth;        if ((age >= 18 and age <= 21) or (age >= 51 and age <= 64)) {            licenseClass = 'C';        } else if (age >= 22 and age <= 30) {            licenseClass = 'B';        } else if (age >= 31 and age <= 50) {            licenseClass = 'A';        } else {            illegalReason = "you are not between 18 and 64 years old";        }    } else {        illegalReason = "you have " + std::to_string(numCrashes) + " accidents";    }    if (licenseClass != 'X') {        std::cout << "You can legally get a Class " << licenseClass << " driver's license\n";    } else {        std::cout << "You cannot legally get a driver's license because " << illegalReason << "\n";    }}``

## Interactive boolean logic calculator​

``#include <iostream>#include <iomanip>#include <string>int main() {    // Ask for the two boolean inputs    std::cout << "Welcome to the Boolean Logic Calculator!\n"              << "Please enter two values of either true or false exactly:\n";        bool inputA;    bool inputB;    // Use std::boolalpha to accept input as either "true" or "false"    std::cin >> std::boolalpha >> inputA >> inputB;    // Ask for the operation    std::cout << "\n\nNow enter a logical operation.\n"              << "Valid options are AND, NAND, OR, NOR, XOR, XNOR (exactly):\n";    std::string op;    std::cin >> op;    // Now compute the result based on op    bool result;    if (op == "AND") {        result = inputA and inputB;    } else if (op == "NAND") {        result = not (inputA and inputB);    } else if (op == "OR") {        result = inputA or inputB;    } else if (op == "NOR") {        result = not (inputA or inputB);    } else if (op == "XOR") {        result = inputA != inputB; // XOR is equivalent to "not equal" for booleans    } else if (op == "XNOR") {        result = inputA == inputB; // XNOR is equivalent to "equals" for booleans    } else {        std::cout << "Error! Invalid choice. Quitting.";                // Using a return statement here to gracefully end the main function,        // which in turn quits the program.        // The 1 signifies a failure to the operating system.        // You will learn more about returns in the Functions chapter.        return 1;    }    std::cout << std::boolalpha; // Set output to show as true/false for booleans    std::cout << "\n\nThe answer of " << inputA << " " << op << " " << inputB << " is " << result;}``

## Computing properties of numbers​

``#include <iostream>int main() {    int value1;    bool isValue1Even;    std::cout << "Input a number: ";    std::cin >> value1;    // Compute the parity (even vs odd) of the number    if (value1 % 2 == 0) {        isValue1Even = true;                std::cout << "Your number is even!\n";        if (value1 == 0) {            // Many people are confused by the parity of zero            std::cout << "But does zero count as an even number?\n";        }    } else {        isValue1Even = false;        std::cout << "Your number is odd!\n";    }    // Compute the sign of the number    if (value1 > 0) {        std::cout << "Your number is positive!\n";    } else if (value1 < 0) {        std::cout << "Your number is negative!\n";    } else {        std::cout << "Zero is neither positive nor negative.\n";    }    // Ask the user for a second number to compare    int value2;    std::cout << "\nNow, input a number again: ";    std::cin >> value2;    // Compute the relative magnitude of the second number compared to the first    if (value1 != value2) {        std::cout << "You entered a different number... ";        if (value1 > value2) {            std::cout << "And it was smaller than the previous one!\n";        } else {            std::cout << "And it was bigger than the previous one!\n";        }    } else {        std::cout << "You entered the same number!\n";    }    // Now check for the "special property"    // Your numbers are special if they are both even and their difference is divisible by seven    int diff = value1 - value2;    bool isValue2Even = value2 % 2 == 0;    if (isValue1Even && isValue2Even && (diff % 7 == 0)) {        std::cout << "Your numbers are special!";    }}``

# Conditions » Examples

``#include <iostream>int main() {    std::cout << "Welcome to the Driver's License Oracle 5500\n";    int yearOfBirth;    std::cout << "Please enter your year of birth: ";    std::cin >> yearOfBirth;    int numCrashes;    std::cout << "Please enter the number of crashes you have had: \n";    std::cin >> numCrashes;    char licenseClass = 'X'; // X is chosen as a default value to signal if we miss one of our cases    std::string illegalReason;    if (numCrashes < 2) {        // Year 2022 at the moment of writing this lesson        int age = 2022 - yearOfBirth;        if ((age >= 18 and age <= 21) or (age >= 51 and age <= 64)) {            licenseClass = 'C';        } else if (age >= 22 and age <= 30) {            licenseClass = 'B';        } else if (age >= 31 and age <= 50) {            licenseClass = 'A';        } else {            illegalReason = "you are not between 18 and 64 years old";        }    } else {        illegalReason = "you have " + std::to_string(numCrashes) + " accidents";    }    if (licenseClass != 'X') {        std::cout << "You can legally get a Class " << licenseClass << " driver's license\n";    } else {        std::cout << "You cannot legally get a driver's license because " << illegalReason << "\n";    }}``
``#include <iostream>#include <iomanip>#include <string>int main() {    // Ask for the two boolean inputs    std::cout << "Welcome to the Boolean Logic Calculator!\n"              << "Please enter two values of either true or false exactly:\n";        bool inputA;    bool inputB;    // Use std::boolalpha to accept input as either "true" or "false"    std::cin >> std::boolalpha >> inputA >> inputB;    // Ask for the operation    std::cout << "\n\nNow enter a logical operation.\n"              << "Valid options are AND, NAND, OR, NOR, XOR, XNOR (exactly):\n";    std::string op;    std::cin >> op;    // Now compute the result based on op    bool result;    if (op == "AND") {        result = inputA and inputB;    } else if (op == "NAND") {        result = not (inputA and inputB);    } else if (op == "OR") {        result = inputA or inputB;    } else if (op == "NOR") {        result = not (inputA or inputB);    } else if (op == "XOR") {        result = inputA != inputB; // XOR is equivalent to "not equal" for booleans    } else if (op == "XNOR") {        result = inputA == inputB; // XNOR is equivalent to "equals" for booleans    } else {        std::cout << "Error! Invalid choice. Quitting.";                // Using a return statement here to gracefully end the main function,        // which in turn quits the program.        // The 1 signifies a failure to the operating system.        // You will learn more about returns in the Functions chapter.        return 1;    }    std::cout << std::boolalpha; // Set output to show as true/false for booleans    std::cout << "\n\nThe answer of " << inputA << " " << op << " " << inputB << " is " << result;}``
``#include <iostream>int main() {    int value1;    bool isValue1Even;    std::cout << "Input a number: ";    std::cin >> value1;    // Compute the parity (even vs odd) of the number    if (value1 % 2 == 0) {        isValue1Even = true;                std::cout << "Your number is even!\n";        if (value1 == 0) {            // Many people are confused by the parity of zero            std::cout << "But does zero count as an even number?\n";        }    } else {        isValue1Even = false;        std::cout << "Your number is odd!\n";    }    // Compute the sign of the number    if (value1 > 0) {        std::cout << "Your number is positive!\n";    } else if (value1 < 0) {        std::cout << "Your number is negative!\n";    } else {        std::cout << "Zero is neither positive nor negative.\n";    }    // Ask the user for a second number to compare    int value2;    std::cout << "\nNow, input a number again: ";    std::cin >> value2;    // Compute the relative magnitude of the second number compared to the first    if (value1 != value2) {        std::cout << "You entered a different number... ";        if (value1 > value2) {            std::cout << "And it was smaller than the previous one!\n";        } else {            std::cout << "And it was bigger than the previous one!\n";        }    } else {        std::cout << "You entered the same number!\n";    }    // Now check for the "special property"    // Your numbers are special if they are both even and their difference is divisible by seven    int diff = value1 - value2;    bool isValue2Even = value2 % 2 == 0;    if (isValue1Even && isValue2Even && (diff % 7 == 0)) {        std::cout << "Your numbers are special!";    }}``