#need help in leap year programming in c

1 messages · Page 1 of 1 (latest)

paper lava
#

#include <stdio.h>

int main() {
int year;
printf("Enter a year: ");
scanf("%d", &year);

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

return 0;

}

odd canopy
#

What do you need help with? Is a test failing? If so, which one and what's the message?

slim zenith
#

Could you please edit your post to add codeblocks around your code (and the error message)?

paper lava
#

this is what's showing

#

We received the following error when we ran your code:
/usr/lib/gcc/x86_64-alpine-linux-musl/14.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: /tmp/ccEkAgCI.o: in function main': /mnt/exercism-iteration/./test_leap.c:59: multiple definition of main'; /tmp/ccLDMnGE.o:/mnt/exercism-iteration/./leap.c:5: first defined here
/usr/lib/gcc/x86_64-alpine-linux-musl/14.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: /tmp/ccEkAgCI.o: in function test_year_not_divisible_by_4_in_common_year': /mnt/exercism-iteration/./test_leap.c:14:(.text+0x18): undefined reference to leap_year'
/usr/lib/gcc/x86_64-alpine-linux-musl/14.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: /tmp/ccEkAgCI.o: in function test_year_divisible_by_2_not_divisible_by_4_in_common_year': /mnt/exercism-iteration/./test_leap.c:19:(.text+0x44): undefined reference to leap_year'
/usr/lib/gcc/x86_64-alpine-linux-musl/14.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: /tmp/ccEkAgCI.o: in function test_year_divisible_by_4_not_divisible_by_100_in_leap_year': /mnt/exercism-iteration/./test_leap.c:24:(.text+0x70): undefined reference to leap_year'
/usr/lib/gcc/x86_64-alpine-linux-musl/14.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: /tmp/ccEkAgCI.o: in function test_year_divisible_by_4_and_5_is_still_a_leap_year': /mnt/exercism-iteration/./test_leap.c:29:(.text+0x99): undefined reference to leap_year'
/usr/lib/gcc/x86_64-alpine-linux-musl/14.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: /tmp/ccEkAgCI.o: in function test_year_divisible_by_100_not_divisible_by_400_in_common_year': /mnt/exercism-iteration/./test_leap.c:34:(.text+0xc2): undefined reference to leap_year'
/usr/lib/gcc/x86_64-alpine-linux-musl/14.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: /tmp/ccEkAgCI.o:/mnt/exercism-iteration/./test_leap.c:40: more undefined references to `leap_year' follow
collect2: error: ld returned 1 exit status
make: *** [makefile:37: tests.out] Error 1

slim zenith
#

Did you edit the header?

paper lava
#

Not there

#

I just wrote the header file here

slim zenith
#

The C exercises require editing the headers IIRC

#

And importing them

odd canopy
#

Ignore the long file paths in the error messages and you’ll see a pattern in what the test runner is telling you. What’s the most common message? Do you understand what it means?

paper lava
#

But how should I proceed now?

slim zenith
#

The crux of the error is undefined reference to 'leap_year'

#

You need to declare that function in the header

paper lava
#

Ok. Will try

fading stag
#

i dont understand the leap year program what they want we do