C/C++ help

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.
1
2
3
4
char andd( char operand1, char operand2){
    if(operand1 == preferred && operand2 == preferred) return preferred;
    else return other;
}

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)
Ok thanks... this seems like it may do the trick. My question is would this

char andd( char operand1, char operand2){
if(operand1 == preferred && operand2 == preferred) return preferred;
else return other;
}

go in at the end of the code some where, it seems may be my code but much shorter
Last edited on
Topic archived. No new replies allowed.