I have almost just started the project and am getting an error with the following code.
The programme is finding out whether or not it is a leap year.
The condition in summary is this;
A leap year has to be divisible by 4 and NOT divisible by 100 except when the year is divisible by 400.
A brief personal description is this;
When a year is divisible by 4, it is a leap year and the function has to evaluate to true. While already in the scope of what I just mentioned above, when it is not divisible by 100, it is still a leap year, but when it is divisible by
#include <stdio.h>
#include <stdbool.h>
bool is_leap_year(int year) {
if((year % 4) != 0){
return false;
} else {
return true;
if((year % 100) != 0){
return true;
} else {
if((year % 400) != 0){
return false;
} else {
return true;
}
}
}
}
int main() {
int year = 1992;
int year_status = is_leap_year(year);
if (year_status == true)
printf("This is a leap year\n");
printf("This is not a leap year\n");
}
Unfortunately when I run the code, it returns both options like this;
This is a leap year
This is not a leap year
2 posts - 2 participants