14,696,499 members
See more:
```#include <stdio.h>

int main()
{
int year;

printf("Enter a year to check if it is a leap year\n");
scanf("%d", &year);

if ( year%400 = 0)
printf("%d is a leap year.\n", year);
else if ( year%100 = 0)
printf("%d is not a leap year.\n", year);
else if ( year%4 = 0 )
printf("%d is a leap year.\n", year);
else
printf("%d is not a leap year.\n", year);

return 0;
}```

What I have tried:

I am not sure what is the wrong in this code?
Posted
Updated 2-Jun-20 6:36am
v3
phil.o 2-Jun-20 9:10am

Please use the green "Improve Question" button and qualify the "What I have tried" part with what you actually tried. No one will do your homework for you.
phil.o 2-Jun-20 11:05am

Problem is, the code that you are showing is not relative in any way to your original question.
Rick York 2-Jun-20 11:49am

You would be better off having a function to call and pass it a year and it returns a boolean value of leap year or not.

Solution 2

The equal-comparison operator in C-language family is `==`, not `=`.
`if (year % 400 == 0) // etc. for other comparisons`
v2
Patrice T 2-Jun-20 10:39am

+5 strait to the point.
phil.o 2-Jun-20 11:05am

Thanks :)

Solution 3

You have two bugs in your code which you must figure out. The first is the missing "=" for the comparison. A typical newbie bugs - but this should also tell you the compiler. Learn to read it.

The second is more complicated because of some edge cases to be read in the wikipedia - leap year calculation.

Solution 1

The point of homework is to do some work.

It's not the solution that's important. It is learning to get to the solution. You may need to learn things you have not yet experience, or didn't quite understand from a lecture or book. Doing them makes a big difference. Learning from the errors along the way is really a big deal and a very good thing.

As for your post - all you've done is give us your homework question - not shown us the least bit of work on your part. Told us where you are stuck.

Being a programmer, at least if you want to be any good, means digging into problems until you can solve them. Sometimes very hard work. Be sure you really want to "Think for a Living".