Check if comboBox SelectedIndex is divisible by 4 in c++
Very new to Visual c++ 2010 Express and as a test program I'm writing a program that can select any date between January 1, 0, and December 31, 2011. Now, I pretty much got the experience I wanted for a different program out of this, but I haven't got it working properly. Obviously, when the month of February is selected, the program needs to know if it is in a leap year or not. So to try to see if the year is divisible by four, I have:
if (fmod(2011 - comboBox3->SelectedIndex, 4) == 0) {
...
}
But when I build it, it gives me the error, "'fmod': identifier not found." Also tried it with the "floor" function. Is there some syntax error here? All I've found about this func开发者_JAVA百科tion leads me to believe I have the right syntax... But does it not work in an if statement or something?
fmod
is a floating point operation. This probably won't be a performance issue for you in a UI, but it's probably overkill for what you're doing.
Try using the %
operator, which is an integer operation:
if ((2011 - comboBox3->SelectedIndex) % 4 == 0) { /* ... */ }
精彩评论