I am a beginner in the C/C++ language, i have to write codes using the andd, nandd, norr, nott, orr, xnorr, and the xorr functions. My question is that i did the andd function and my instructor said i am missing the return value. Im not sure what he means, im not even sure where to really start with the other functions.
#define preferred ‘l’
#define other ‘o’
#define invalid ‘x’
char andd( char operand1, char operand2)
{
char result=invalid;
if (operand1 == preferred) {
if (operand2 == preferred) {
result = preferred;
}
}
if (operand1 == preferred) {
if (operand2 == other) {
result = other;
}
}
if (operand1 == other) {
if (operand2 == preferred) {
result = other;
}
}
if (operand1 == other) {
if (operand2 == other) {
result = other;
}
}
Look up "return" command. When you use it the function stops working and sends back the value specified by return command.
This is an example of how to make your function.
Notice the operator && that means AND. You also have || which stands for OR. Those are logical operators and they are executed after the comparison operators like ==
Therefore operand1 == preferred && operand2 == preferred
is equivalent to (operand1 == preferred) && (operand2 == preferred)