I run my C code in vs2010 (win32 console application). It was compiled as c++ application.
#include "stdafx.h"
#define YES 1;
#define NO 0;
// function to determine if an integer is even
int isEven(int number)
{
int answer;
if ( number % 2 == 0)
answer = YES;
else
answer = NO;
return answer;
}
int main()
{
int isEven(int number);
if (isEven(17) == YES)
printf("yes ");
else
printf("no ");
if ( isEven(20) == YES)
printf("yes\n");
else
printf("no\n");
return 0;
}
Compiler error as below.
p300.cpp(18): error C2181: illegal else without matching if
p300.cpp(30): error C2143: syntax error : missing ')' before ';'
p300.cpp(30): error C2059: syntax error : ')'
p300.cpp(31): warning C4390: ';' : empty controlled statement found; is this the intent?
p300.cpp(33): error C2181: illegal else without matching if
p300.cpp(37): error C2143: syntax error : missing ')' before ';'
p300.cpp(37): error C2059: syntax error : ')'
p300.cpp(38): warning C4390: ';' : empty controlled statement found; is this the intent?
p300.cpp(40): error C2181: illegal else without matching if
Then I also tried to insert several of { }
for each of if-else
condition statement, but the code still compiled failed. What's wrong with my code? Thank you.