3 votes
Accepted

cs50 plurality non-void function does not return a value in all control paths error

The error means a path that does not take the if branch or the else branch will not return a boolean, since the returns are embedded in those blocks. Think about this comment //if input name does not ...
user avatar
3 votes

Plurality is being failed by check50 when it works in my terminal (PSET3)

Resolved. I feel like a complete idiot. printf("%s \n", winner[i]); should be printf("%s\n", winner[i]);
user avatar
  • 31
3 votes
Accepted

PSET 3 Plurality - Program works but also returns invalid vote?

Pretty straightforward problem. Your vote function ALWAYS returns false, even after registering the vote. If false is returned to main, it'll print the invalid vote message. If vote() succeeds in ...
user avatar
  • 63.1k
2 votes
Accepted

pset 3 plurality code help

for (int i = 0; i < candidate_count; i++) { if (candidates[i].votes >= maxvote) { maxvote = candidates[i].votes; winner = candidates[i].name; ...
user avatar
  • 701
2 votes

Global Variable vs Local variables?

candidate_count is not declared in main. It's a global variable (declared outside of main) on line 20 in the distribution file plurality.c at the time of this writing. The definition of main starts ...
user avatar
  • 17.4k
2 votes
Accepted

pset3 plurality - trouble implementing a linear sort

The problem with using recursion here, is that it executes x times not only the part with the sorting but also the printing part. If you want to go with recursion you could split into two separate ...
user avatar
  • 1,541
2 votes
Accepted

Problem set 3 Plurality ISSUE cs50

If you fix the missing semicolon that @DinoCoderSaurus mentioned, this works fine. I suspect you hadn't compiled it after writing your function, so the default return false was still being used.
user avatar
  • 18.3k
2 votes

Plurality works perfectly with debug50, but it does not without it

You've stumbled on a known issue with debug50. It will, under unique circumstances, mask a segmentation fault. But, you can be sure that the seg fault is real. You'll need to isolate the offending ...
user avatar
  • 63.1k
2 votes
Accepted

Plurality Pset 3 I need Help

Segfault is a memory error which is caused due to leakage in memory or aka bytes I need to see the whole code Remember you only need to print the name of the candidate(s) once it's vote matches the ...
user avatar
1 vote
Accepted

check50 for plurality

Try this election: 3 candidates: a, b, c and 2 voters who vote for c. It reports a and b as (tied) winners. That's because c's votes are not considered in the first for (int i = 0; i < voter_count; ...
user avatar
1 vote
Accepted

PSET3 - Plurality. Check50 is showing three error messages. Unable to find any mistakes in my code. Please help

You may be happy (or frustrated) to know that the errors in your code are relatively trivial. I ran your code through debug50 and set a breakpoint at the print_winner function. It looks like you have ...
user avatar
1 vote

Plurality exercise - error messages

This if (candidates[j].votes==candidate_count-i) may or may not be the winner. In an election with 3 candidates and 3 voters, a candidate can win with 3 votes. In an election with 5 candidates and 3 ...
user avatar
1 vote
Accepted

Plurality CS50 Week3 pset3

When You are using else if It executes either of the statements. Remove else if statement . Make another loop(Independent of the previous loop) and then print the name of candidate if it has maximum ...
user avatar
  • 72
1 vote
Accepted

I changed typedef struct in Plurality in problem set 3, is there any problem?

If it compiles, runs, and passes check50, you can change it. I don't think it'll pass check50 though. Keep in mind that, for some programs, particularly where there are instructiions not to change ...
user avatar
  • 63.1k
1 vote
Accepted

Plurality problem

It should not seg fault if the election has 9 candidates. Remember 9 is the maximum number of candidates. Any election with fewer will seg fault in the vote function for loop. The loop should only ...
user avatar
1 vote
Accepted

Plurality Clarification

You can edit whatever you need to in order to make the logic work so that the program produces the expected results. If in the end, the code you write produces the same logical output, it should be ...
user avatar
1 vote
Accepted

Plurality starter code clarification

candidate is the datatype. It is a custom datatyoe (also called a "user-defined" datatype). The name of the variable is candidates plural. You will find the datatype defined either in the ...
user avatar
1 vote
Accepted

cs50 plurality invalid vote

It is normal. If you take a close look at the code provided, the vote function for now returns false and the main function will print invalid vote if the return value is false. Once implemented, the ...
user avatar
  • 957
1 vote
Accepted

Pset3 Plurality: program runs fine when I check manually, but Check50 disagrees

So, I see a logic error in this bit of code: if (winner_int < candidates[i].votes) { winner = candidates[i].name; } Since you set winner_int equal to the number of votes that candidate[0] and ...
user avatar
1 vote

Plurality test passing on all except one

Yea, in true rubber duck fashion I figured out the problem immediately after posting this..., why would I ever want to += instead of just =...
user avatar
1 vote

PSet 3 Plurality keeps getting 'segmentation fault'

you are acsessing a part of an array that you dont have acsess to
user avatar
1 vote
Accepted

Calling 'Vote' function in Plurality (Problem Set 3)

No that's get_string() that function is what you use to prompt the user for their vote, and whatever the user inputs it will be stored in the variable called name. The vote function when called would ...
user avatar
  • 701
1 vote

why does it not return a value for bool?

The return false; should be the last line of your function, after the loop, there is nothing to do in that else. Rationale: If you have a name match, you know the vote is valid. But if you have a ...
user avatar
  • 20.7k
1 vote
Accepted

Problem with plurality

The problem is in this condition in your second 'for' loop: for (int c = 0 ; c < i - candidate_count - 1 ; c++). Let's see: Before execute the second loop i = 0 and c = 0. To run the code 'c < i ...
user avatar
  • 1,541
1 vote
Accepted

Pset3: Plurality; Code doesn't consider command line arguments expect the first one!

Consider the for loop in your vote() function: It compares the candidate name with the name introduced by the voter. In the very first pass (i = 0) what happens when the candidate name and the name ...
user avatar
  • 1,541
1 vote
Accepted

CS50 plurality will not return any answers

yo"re almost there. You made a small mistake in your implementation of your function print_winner() . If you don't see it I'd suggest the use of debug50 to check the value of your variables at every ...
user avatar
  • 1,541
1 vote
Accepted

why is this wrong?cs50 pset3 plurality

To help facilitate people giving you answers in the future it helps if you can provide more context on the issues you're having. What error you're seeing and what line does it start on. That said you'...
user avatar
  • 43
1 vote

pset 3 plurality code help

Your code is incrementing maxvote every time your if statement is true.. The goal is to get the max number of votes and see then check if who are the candidates that have the same number of votes to ...
user avatar
  • 701
1 vote
Accepted

PSET3-Plurality. Check50 doesn't re

If you know you're printing the right answer, then it must be your formatting when you print. Try removing the space when you print each name. Use this printf ("%s\n", winners[i]); instead of printf ("...
user avatar
  • 302
1 vote

Plurality vote strange errors

There is no data that will show you what check50 sees. That is because program violates this instruction from the spec: You should not modify anything else in plurality.c other than the ...
user avatar

Only top scored, non community-wiki answers of a minimum length are eligible