`I've been trying this code to show if a number that I type is even or odd, but it gets an error when I run it:
ERROR:`
make -s
./main.c:8:13: error: invalid operands to binary expression ('char ()' and 'int')
if(numero % 2 == 0){
~~~~~~ ^ ~
1 error generated.
make: *** [Makefile:10: main] Error 1
exit status 2
CODE:
#include <stdio.h>
int main(void) {
char number();
printf("Enter a number: ");
scanf("%d", &number);
if (number % 2 == 0) {
printf("%d is even", number);
} else {
printf("%d is odd", number);
}
return 0;
}
I tried searching the same error here, but it doesn't fix my error
char number();declares a function prototype because of the round brackets at the end. The compiler thinksnumberis a function returning achar. Therefore innumberis a function pointer and it makes no sense to divide it by 2.numbershould be declared as anintif you are using%di.e.