I have the weirdest exercise I've ever seen: I have to find a leap year by scanning a year in the console and to control if that is a leap year.
I can only use + - / * % as arithmetical operators; I am not allowed to use any other operators or functions.
Here is what I have so far:
int year = 0;
bool b = false;
printf ("Type in a year: ");
int helpVar = 1000;
for (int i = 0; i < 4; i++) {
year += (getchar() - '0') * helpVar;
helpVar = helpVar / 10;
}
b = (((year % 4) + (year % 100) + (year % 400)) + 1) % 2;
So I don't understand what I am doing wrong here. It works so far, the only case that's freaking me out is for year "1900". It shouldn't be a leap year, but appears to, by my code.
What am I missing here?