diff --git a/ee.h b/ee.h index cbb6d5c..10d30f7 100644 --- a/ee.h +++ b/ee.h @@ -107,9 +107,11 @@ evaluate(STACK* target_stack, int operator){ break; case '!' : operands = getOperands(target_stack, 1); - if ((operands[0] != floor(operands[0]))) + if ( (operands[0] != floor(operands[0])) || (operands[0] < 0)) { ERR_INVALID_FACTORIAL = 1; } - value = fact((int)operands[0]); + else{ + value = fact((int)operands[0]); + } break; default : break; @@ -151,14 +153,14 @@ reportErrors(){ * ERR_INVALID_INPUT. */ int errors = 0; - if (ERR_NS_OPERANDS){ - printf("Error: insufficient operands.\n"); errors++; + if (ERR_INVALID_INPUT){ + printf("Error: Unexpected input.\n"); errors++; } else if (ERR_NS_OPERATORS){ printf("Error: insufficient operators.\n"); errors++; - } else if (ERR_INVALID_INPUT){ - printf("Error: Unexpected input.\n"); errors++; + } else if (ERR_NS_OPERANDS){ + printf("Error: insufficient operands.\n"); errors++; } else if (ERR_INVALID_FACTORIAL){ - printf("Error: only integer factorials are supported.\n"); errors++; + printf("Error: Factorials are only supported for positive integers.\n"); errors++; } return errors; }