Use the AND and OR Operators

less than 1 minute read

The code has been modified slightly and now uploaded to the site.

Question

<— Return Home

324.cpp

#include <iostream>
using namespace std;

int main(){
    int input;
    bool andDivisible = false;
    bool orDivisible = false;
    bool orDivisibleNotBoth = false;

    std::cout << "Enter an integer: \n";
    std::cin >> input;

    if (input % 5 == 0 && input % 6 == 0){
        andDivisible = true;
    }
    if (input % 5 == 0 || input % 6 == 0){
        orDivisible = true;
    }
    if (input % 6 == 0 ^ input % 5 == 0){
        orDivisibleNotBoth = true;
    }

    std::cout << "Is " << input << " divisible by 5 and 6? " << andDivisible << "\n";
    std::cout << "Is " << input << " divislbe by 5 or 6? " << orDivisible << "\n";
    std::cout << "Is " << input << " divisible by 5 or 6, but not both? " << orDivisibleNotBoth << "\n";
}

<— Return Home