C++: Using "OR" Boolean Operator [ "||" ]

by matt392 in Circuits > Software

7 Views, 0 Favorites, 0 Comments

C++: Using "OR" Boolean Operator [ "||" ]

oroperator.jpg

C++ Program that uses the "OR" boolean operator. Also uses if-else and else-if statements.

#include <iostream>
#include <string>

using namespace std;

int main()

{ // start main function

string linuxDistribution;

cout << "Enter Linux distribution: ";
cin >> linuxDistribution;

if (linuxDistribution == "Debian" || linuxDistribution == "debian")
{
cout << "Debian uses apt-get.";
} // end if

else if (linuxDistribution == "Fedora" || linuxDistribution == "fedora")
{
cout << "Fedora is part of Red Hat.";
} // end else if

else if (linuxDistribution == "OpenSuse" || linuxDistribution == "opensuse")
{
cout << "OpenSuse uses Yast.";
} // end else if

else if (linuxDistribution == "Kali" || linuxDistribution == "kali")
{
cout << "Kali is a security distribution.";
} // end else if

else if (linuxDistribution == "Slackware" || linuxDistribution == "slackware")
{
cout << "Slackware is an advanced Linux system.";
} // end else if

else if (linuxDistribution == "Arch" || linuxDistribution == "arch")
{
cout << "Arch uses 'pacman'.";
} // end else if

else
{
cout << "There are over 300 Linux distributions!";
} // end else

return 0;

} // end main function

Supplies

codeblockslogo.png
desktopcomputer.jpg
  1. Desktop or laptop compuiter
  2. Code::Blocks IDE for C++

C++ Code Using "OR" Operator " || "

2ndoroperator.jpg

C++ Program that uses the "OR" boolean operator. Also uses if-else and else-if statements.

#include <iostream>
#include <string>

using namespace std;

int main()

{ // start main function

string linuxDistribution;

cout << "Enter Linux distribution: ";
cin >> linuxDistribution;

if (linuxDistribution == "Debian" || linuxDistribution == "debian")
{
cout << "Debian uses apt-get.";
} // end if

else if (linuxDistribution == "Fedora" || linuxDistribution == "fedora")
{
cout << "Fedora is part of Red Hat.";
} // end else if

else if (linuxDistribution == "OpenSuse" || linuxDistribution == "opensuse")
{
cout << "OpenSuse uses Yast.";
} // end else if

else if (linuxDistribution == "Kali" || linuxDistribution == "kali")
{
cout << "Kali is a security distribution.";
} // end else if

else if (linuxDistribution == "Slackware" || linuxDistribution == "slackware")
{
cout << "Slackware is an advanced Linux system.";
} // end else if

else if (linuxDistribution == "Arch" || linuxDistribution == "arch")
{
cout << "Arch uses 'pacman'.";
} // end else if

else
{
cout << "There are over 300 Linux distributions!";
} // end else

return 0;

} // end main function