Question regarding plurality program in pset3.

Dear All

I am really new to programing.

It took me a lot of efforts to complete my pset3 problem “plurality”. It is compiling and giving expected results in CS50 sandbox. But when I use “check50 cs50/problems/2020/x/plurality” to check my programe it gives me following errors. Please help.

running clang plurality.c -o plurality -std=c11 -ggdb -lm -lcs50…
running clang plurality_test.c -o plurality_test -std=c11 -ggdb -lm -lcs50…
plurality_test.c:109:13: error: use of undeclared identifier ‘candidate_count’
candidate_count = 3;
^
plurality_test.c:123:26: warning: implicit declaration of function ‘vote’ is
invalid in C99 [-Wimplicit-function-declaration]
printf("%s", vote(“Alice”) ? “true” : “false”);
^
plurality_test.c:163:13: warning: implicit declaration of function
‘print_winner’ is invalid in C99 [-Wimplicit-function-declaration]
print_winner();
^
2 warnings and 1 error generated.

I do understand the errors but here are few points which aren’t clear to me.

  1. I didn’t even use the term “candidate_count” in my code, why am I getting error related to this.

  2. Also I didn’t write any function called “print_winner”. I simply printed results within main function by other means. Why am I getting errors related to this?

  3. Again I haven’t written any function called vote. I gave it the name votes. Why there are errors related to functions or terms which I didn’t even use?

My code is working fine in CS50 sandbox and giving proper results.

First, let me caveat this by saying I can’t know exactly what check50 is doing, so I can only make a logical guess.

I took a look at the plurality task, and I believe you have not followed the instructions as given.

The instructions say to download the distributed plurality.c file, and modify only the contents of the methods vote and print_winner. All three errors are related to variables or functions found in the distributed plurality.c. Evidently, check50 expects them to be in your program.

For example, the variable candidate_count is declared on line 20 of the distributed plurality.c file. check50 apparently tests the code by using that variable. As you say you didn’t even use the term candidate_count in your version of the program, that would explain why check50 produced the error. The same explanation applies to the other two errors.

Also, the Github discussion forum for CS50 etc can be found here

We are happy to try to assist here in the General Github community, but you’re more likely to encounter your fellow students in that forum.

Thank You so much. You guessed it absolutely right. It was the exact problem.