You are on page 1of 5

/******************************************************************************

Online C++ Compiler.

Code, Compile, Run and Debug C++ program online.

Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>

using namespace std;

int main()

string gates[3] ={"AND", "OR", "NOT"};

int gate, a, b;

for(int i=0; i<3; i++)

cout << i+1 << ":" << gates[i] << "\n";

cout << "Enter any number associated with particular gate: ";

cin >> gate;

if(gate<3){
cout << "Enter numbers only 0 or 1 \n";

cout << "Enter number1: ";

cin >> a;

if(a==0 || a==1){

cout << "Enter number2: ";

cin >> b;

if(b==0 || b==1){

switch (gate)

case 1:

if(a==1 && b==1)

cout << "1";

else{
cout << "0";

break;

case 2:

if(a==0 && b==0)

cout << "0";

else{

cout << "1";

break;

else{

cout << "Invalid number2";

}
}

else{

cout << "Invalid number1 ";

else if(gate==3){

cout << "Enter either 0 or 1: ";

cin >> a;

if(a==0 || a==1){

switch (a)

case 0:

cout << "1";

break;

case 1:
cout << "0";

break;

else{

cout << "Invalid number type only 0 or 1";

else{

cout << "Invalid gate no.";

return 0;

You might also like