Hi, I am having a problem with this very simple piece of code that I am learning from a book.
Code:#include <stdio.h> /*#define OVER_TWENTY_FINE 75*/ /*problem*/ main() { int fine = 5, number_of_a = 11, OVER_TWENTY_FINE = 75; /*solution*/ if(number_of_a <= 10) ++fine; else fine += OVER_TWENTY_FINE; printf("\nfine is %d." , fine); }
As you can see this is a simple "if" "else" decision. I originally had OVER_TWENTY_FINE in a "#define" statement before main(). Now I have it commented out, and have instead declared it as an integer. This is because when I was using it as a #define statement it wouldn't let the "if else" work. I would get these two errors:
error C2059: syntax error : 'if'
error C2181: illegal else without matching if
After I commented it out and started declaring it as int, the code works fine. I can't see what could be wrong with this. Suggestions??.....



LinkBack URL
About LinkBacks



