Dear CLion Community,
I've been studying a programming book, titled: "Beginning C: 5th Edition" by Ivor Horton. In it, there's a brief tutorial that I can't seem to compile. I highly doubt the error is in the book, since this author is a well-regarded and well-respected.
Here it is:
// Program 3.3 Using nested ifs to analyze numbers
#include <limits.h> // For LONG_MAX
long test = 0L; // Stores the integer to be checked
printf("Enter an integer less than %ld:", LONG_MAX);
scanf(" %ld", &test);
// Test for odd or even by checking the remainder after dividing by 2
if(test % 2L == 0L)
printf("The number %ld is even", test);
// Now check whether half the number is also even
if((test/2L) % 2L == 0L)
printf("\nHalf of %ld is also even", test);
printf("\nThat's interesting isn't it?\n");
printf("The number %ld is odd\n", test);
Yet, the compiler is giving me these errors.
/Applications/CLion.app/Contents/bin/cmake/bin/cmake --build /Users/frederickpina/Library/Caches/CLion12/cmake/generated/6fd947b6/6fd947b6/Debug --target all -- -j 2
Scanning dependencies of target HelloWorld
[ 50%] Building CXX object CMakeFiles/HelloWorld.dir/main.cpp.o
/Users/frederickpina/ClionProjects/HelloWorld/main.cpp:13:24: warning: if statement has empty body [-Wempty-body]
if(test % 2L == 0L);
/Users/frederickpina/ClionProjects/HelloWorld/main.cpp:13:24: note: put the semicolon on a separate line to silence this warning
/Users/frederickpina/ClionProjects/HelloWorld/main.cpp:24:5: error: expected expression
1 warning and 1 error generated.
make: *** [CMakeFiles/HelloWorld.dir/main.cpp.o] Error 1
make: *** [CMakeFiles/HelloWorld.dir/all] Error 2
make: *** [all] Error 2
Can anyone please help ? Thanks !!!!
Attachment(s):Screen Shot 2015-12-21 at 3.18.16 PM.png