#Help with test ( in C ) I don't know what's wrong with it, first time using exercism

1 messages · Page 1 of 1 (latest)

fringe karma
#
#include <stdio.h>


int main() {
    int number = 10, sum_of_squares = 0, square_of_sum = 0, difference_of_squares;
    for (int i = 1; i <= number; i++) {
        sum_of_squares += i * i;
    }

    for (int i = 1; i <= number; i++) {
        square_of_sum += i;
    }

    square_of_sum = square_of_sum * square_of_sum;

    difference_of_squares = square_of_sum - sum_of_squares;

    printf("A diferença entre o quadrado da soma e a soma dos quadrados dos primeiros %d números naturais é: %d\n", number, difference_of_squares);

    return 0;
}```
#
#define DIFFERENCE_OF_SQUARES_H

unsigned int sum_of_squares(unsigned int number);
unsigned int square_of_sum(unsigned int number);
unsigned int difference_of_squares(unsigned int number);

#endif```
boreal hare
#

Could you edit your prior message and wrap your code in codeblocks (```)?

#

Could you also share the test output as text using a codeblock?

fringe karma
#
We received the following error when we ran your code:

/usr/lib/gcc/x86_64-alpine-linux-musl/13.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: /tmp/cckDlIFp.o: in function `main':
/mnt/exercism-iteration/./test_difference_of_squares.c:58: multiple definition of `main'; /tmp/ccdfClKm.o:/mnt/exercism-iteration/./difference_of_squares.c:5: first defined here
/usr/lib/gcc/x86_64-alpine-linux-musl/13.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: /tmp/cckDlIFp.o: in function `test_square_of_sum_1':
/mnt/exercism-iteration/./test_difference_of_squares.c:14:(.text+0x18): undefined reference to `square_of_sum'
/usr/lib/gcc/x86_64-alpine-linux-musl/13.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: /tmp/cckDlIFp.o: in function `test_square_of_sum_5':
/mnt/exercism-iteration/./test_difference_of_squares.c:19:(.text+0x48): undefined reference to `square_of_sum' ```
#

```/usr/lib/gcc/x86_64-alpine-linux-musl/13.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: /tmp/cckDlIFp.o: in function test_square_of_sum_100': /mnt/exercism-iteration/./test_difference_of_squares.c:24:(.text+0x78): undefined reference to square_of_sum'
/usr/lib/gcc/x86_64-alpine-linux-musl/13.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: /tmp/cckDlIFp.o: in function test_sum_of_squares_1': /mnt/exercism-iteration/./test_difference_of_squares.c:29:(.text+0xa8): undefined reference to sum_of_squares'
/usr/lib/gcc/x86_64-alpine-linux-musl/13.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: /tmp/cckDlIFp.o: in function test_sum_of_squares_5': /mnt/exercism-iteration/./test_difference_of_squares.c:34:(.text+0xd8): undefined reference to sum_of_squares'
/usr/lib/gcc/x86_64-alpine-linux-musl/13.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: /tmp/cckDlIFp.o: in function test_sum_of_squares_100': /mnt/exercism-iteration/./test_difference_of_squares.c:39:(.text+0x108): undefined reference to sum_of_squares'
/usr/lib/gcc/x86_64-alpine-linux-musl/13.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: /tmp/cckDlIFp.o: in function test_difference_of_squares_1': /mnt/exercism-iteration/./test_difference_of_squares.c:44:(.text+0x138): undefined reference to difference_of_squares'
/usr/lib/gcc/x86_64-alpine-linux-musl/13.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: /tmp/cckDlIFp.o: in function test_difference_of_squares_5': /mnt/exercism-iteration/./test_difference_of_squares.c:49:(.text+0x168): undefined reference to difference_of_squares'
/usr/lib/gcc/x86_64-alpine-linux-musl/13.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: /tmp/cckDlIFp.o: in function test_difference_of_squares_100': /mnt/exercism-iteration/./test_difference_of_squares.c:54:(.text+0x198): undefined reference to difference_of_squares'
collect2: error: ld returned 1 exit status
make: *** [makefile:37: tests.out] Error 1

#

Do you want what have in Tests too?

#

Help with test ( in C ) I don't know what's wrong with it, first time using exercism

boreal hare
#

You shouldn't have a main() in your code. The unit test is the entry point.

#

Are you running the tests? How?

fringe karma
#

or a main in other local/code?

#

I'm learning programming now, because it I "guess" is correct, and because in vscode it works!

#

Just in exercism don't work, and now I'm here needing help

boreal hare
#

When you say it "works" in vscode, what does that mean?

#

Does it run the tests?

#

Do you understand how testing code works and how test driven development works?

fringe karma
boreal hare
fringe karma
#

Ty, I gonna read and give a feedback if my code works!

fringe karma
#

@boreal hare 🤦‍♂️ I'd just need to use

unsigned int square_of_sum(unsigned int number);
unsigned int difference_of_squares(unsigned int number);
and not
int number = 10, sum_of_squares = 0, square_of_sum = 0, difference_of_squares;

in my main
😩