I need help fixing my code, its focused on Booleans and Implies

Viewed 29

I will be posting my code below. I created functions for all of the Booleans as needed. Im not sure if they are all correct but I believe they are. My code is supposed to test 4 statements for all combinations and print the TRUE ones. When I tried to run it before while it was working, I got answers that didnt match with the Truth Table generator. enter image description here



#include <iostream>
using namespace std;

//Functions//

//NAND
bool NAND(bool a, bool b) {
 return !(a && b);
}

//XOR
bool XOR(bool a, bool b) {
 return (a != b);
}

//NOR
bool NOR(bool a, bool b) {
 return !(a or b);
}

//XNOR
bool XNOR(bool a, bool b) {
 return (a == b);
}
//IMPLIES
bool IMPLIES(bool a, bool b) {
 return (a == b or b == 1);
}

int main(){
 
int a[8] = { 0, 0, 0, 0, 1, 1, 1, 1 };
int b[8] = { 0, 0, 1, 1, 0, 0, 1, 1 };
int c[8] = { 0, 1, 0, 1, 0, 1, 0, 1 };



int i = 0;
int bad = 0;

//(A nor C) xor B
while (i < 8)
 {
     if (XOR( !(a[i] or c[i]) , b[i])){
         cout << "The following statement: (A nor C) xor B is True for A= " << a[i] << " B= " << b[i] << " C= " << c[i] << endl; 
         bad++;
     }
     i++;
 }

// (B implies C) nand(A nor B)
i = 0;
bad = 0;
while (i < 8)
{
 if (NAND(IMPLIES(b[i],c[i]), NOR(a[i],b[i])) {
     cout << "The following statement: (A nor C) xor B is True for A= " << a[i] << " B= " << b[i] << " C= " << c[i] << endl;
     bad++;
 }
 i++;
}

//) (A xor B) implies(B xnor C)
i = 0;
bad = 0;
while (i < 8){
 if (IMPLIES(XOR(a[i],b[i]),XNOR(b[i],c[i])) {
     cout << "The following statement: (A nor C) xor B is True for A= " << a[i] << " B= " << b[i] << " C= " << c[i] << endl;
     bad++;
 }
 i++;
}
//) (A implies B) implies !C
i = 0;
bad = 0;
while (i < 8)
{
 if (    IMPLIES(IMPLIES(a[i],b[i]) , !c[i])) {
     cout << "The following statement: (A implies B) implies !C is True for A= " << a[i] << " B= " << b[i] << " C= " << c[i] << endl;
     bad++;
 }
 i++;
}
}





0 Answers
Related