0
Expected expression before â=â token
Hello guys, I would really appreciate if someone can help me find my mistake In this code: #include <stdio.h> int main() { int y; int x=400; int c=4; int d=100; printf("Enter a year to find out if it is a leap:\n"); scanf("%i",&y); if(y%x==0||y%c==0&&y%d!==0)(printf("%i is a leap year.",&y)); else(printf("%i is not a leap year.",&y)); return 0; }
3 RĂ©ponses
+ 2
In line with leap year check you should change y%d!==0 on y%d!=0, because there is no such an operator !==. Also, in printf function you should change &y on y, since your code will output address of variable y, but not its value:
#include <stdio.h>
int main() {
int y;
int x=400;
int c=4;
int d=100;
printf("Enter a year to find out if it is a leap:\n");
scanf("%i",&y);
if(y%x==0||y%c==0&&y%d!=0)(printf("%i is a leap year.",y));
else(printf("%i is not a leap year.",y));
return 0;
}
+ 1
Alexus100 thanks dude, but your answer didnât really help, i asked my friend and the code is supposed to go like this:
#include <stdio.h>
int main()
{
int y;
printf("Enter a year:\n");
scanf("%i", &y);
if ((y % 400 == 0) || ((y % 4 == 0) && (y % 100 != 0))){
printf("%i is a leap year", y);
}
else{
printf("%i is not a leap year", y);
}
return 0;
}
0
I can add int x, c and d instead of 400, 4 and 100, but things would work anyway, I tested it runned it, and all is fine. One more thing:
y%100!=0 is saying that when y is devided by 100 there are certainly remainders
y%100!==0 is saying that y devided by 100 should not be equal to 0 but it could be equal to 0