Questions tagged [plurality]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
1 vote
2 answers
21 views

Plurality - Test does not pass for the case of Bob

I'm trying to run check50 on plurality and I can pass all the tests except for the case of Bob where Bob's name is not printed. :( print_winner identifies Bob as winner of election expected "...
Craig D'Silva's user avatar
0 votes
1 answer
19 views

PSET3 Plurality - void print_winner(void) function

I am having a lot of difficulty with conceptualizing this function and applying this weeks lessons on algorithms. With the code below, what I have been trying to do is to mimic a selection sort, ...
Jeff's user avatar
  • 21
0 votes
0 answers
20 views

Problem of pset3 plurality

This code can run, but the outcome isn't right.I checked many times, but I still can't figure it out.I wish someone can help me. Here is the function "print_winner" of my code:(I guess the ...
Lea's user avatar
  • 1
0 votes
1 answer
64 views

Pset3 plurality print winner doesn't work

What's wrong with my code? The program works when I try it manually but when I check it for check50 it returns ":(" for all "print_winner" function. I spent a lot of time on this ...
e-zawadzka's user avatar
0 votes
1 answer
13 views

calling the first element in struct

I have defined an array of pairs of elements using struct and I'm trying to call (and sort) it using one of the elements (I'm not sure if element is the right term for it) for example, I have typedef ...
blueberry's user avatar
0 votes
1 answer
33 views

pset3: Plurality - check50 errors despite code working

My code appears to work, successfully printing the candidate/candidates with the most votes. However, I fail all of check50’s ‘print_winner’ function tests. I have looked around for a while online, ...
TheWanderingAmateur's user avatar
0 votes
1 answer
29 views

It doesn't print Alice as the winner

when I try my code manually it does everything correct, but when I run Check 50, it says following ":( print_winner identifies Alice as winner of election print_winner function did not print ...
mario alberto ortiz salazar's user avatar
0 votes
1 answer
122 views

having problems with check50 in plurality

I seem to have a working program but whenever i run Check50 it gives me all green except for two of the lines which for some reason don't seem to think it works. #include <cs50.h> #include <...
Schmilp's user avatar
0 votes
1 answer
126 views

Pset3 Plurality - not able to get the right output

Here is my code for the print_winner() function. I am pretty sure the problem is here because I have checked other parts of the code which seem alright. void print_winner(void) { for (int i = 0; i ...
Soumik's user avatar
  • 15
0 votes
1 answer
53 views

Pset 3 Plurality "use of undeclared identifier"

I'm not sure I understand why here: // Update vote totals given a new vote bool vote(string name) { for (int j = 0; j < candidate_count; j++) { if (strcmp(name, candidates[j].name) =...
jiayou's user avatar
  • 17
0 votes
1 answer
24 views

PSet3 Plurality - Segmentation Fault when exiting main

My code seems to function properly until I try to exit main. At this point it reports a segmentation fault. This only occurs when there is a tie. Here is my code: #include <stdio.h> #include <...
Thomas Gallaher's user avatar
0 votes
1 answer
275 views

CS50 problem set 3, vote function problem

Good evening. I have a problem with problem set 3 (plurality) https://cs50.harvard.edu/x/2022/psets/3/plurality/ "vote" function always return "false". I tried different ways, but ...
Bagazega's user avatar
0 votes
1 answer
236 views

check50 errors in pset3 plurality

#include <cs50.h> #include <stdio.h> #include <string.h> // Max number of candidates #define MAX 9 // Candidates have name and vote count typedef struct { string name; int votes; } ...
Aayed Hassan's user avatar
0 votes
2 answers
419 views

Plurality: Code does not print out the winner

My code does not print out the winners at all...It only outputs their names. Is anybody able to pick out what's incorrect or if the code is missing something? Many thanks in advance :) #include <...
Soya's user avatar
  • 5
0 votes
1 answer
52 views

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

Attached are my two functions. The code did not print winner for two inputs and also did not print all names in case of tie. // Update vote totals given a new vote bool vote(string name) { // TODO ...
Sumith's user avatar
  • 5
0 votes
1 answer
55 views

Plurality exercise - error messages

I am trying to do the Plurality exercise for problem set 3, but when I type this to test it, I get errors even though I believe my program looks correct. check50 cs50/problems/2021/x/plurality I get ...
David's user avatar
  • 101
0 votes
1 answer
78 views

Plurality CS50 Week3 pset3

// Print the winner (or winners) of the election void print_winner(void) { int max =0; for(int i=0; i<candidate_count; i++) { if(candidates[i].votes>candidates[i+1].votes) ...
user01's user avatar
  • 7
0 votes
1 answer
32 views

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

"You should not modify anything else in plurality.c other than the implementations of the vote and print_winner functions (and the inclusion of additional header files, if you’d like)." I ...
Guilherme H's user avatar
0 votes
0 answers
266 views

Help on Plurality Pset3

I'm trying to solve assignment "Plurality" of Problem set 3. However, check50 didn't prove to be quite useful for me this time. I'm having only one error message saying "print_winner&...
Zoltán Uhlár's user avatar
0 votes
1 answer
73 views

Plurality problem

I ran check50 on my code and it worked fine on everything except in dealing with invalid votes, so I tested it by debugging and fount out that a segmentation error occurs while debugging, and then ...
Mohamed Hassan's user avatar
0 votes
1 answer
24 views

Plurality Clarification

Here, can I edit return false because it seems to be in the wrong place for me (to return false at any time and/or case it was called in), or I should edit only the TODO code section?
Mohamed Hassan's user avatar
0 votes
1 answer
26 views

Plurality starter code clarification

Previously, we 've been indicating an array by typing its datatype at first, and then the rest of the syntax how does candidate here is typed instead of the datatype ?
Mohamed Hassan's user avatar
0 votes
1 answer
17 views

Printf works fine if arr[0] is the largest after sorting, but not if another element is moved to that position. Why?

I am trying to sort a typedef struct array and print out those elements that have the largest number. I can get the answer I want, but if the element that is largest is NOT what was originally in the ...
Lperino's user avatar
  • 14
0 votes
0 answers
90 views

CHECK50 for Plurality shows bug which manual testing can't find

Could anyone perhaps help me figure out what's wrong with the code below? When I check it manually, it works every time, in every scenario I can think of, but when I run check50 on it, I get ":( ...
Rizvan Jacob's user avatar
0 votes
1 answer
133 views

cs50 plurality invalid vote

I'm working on plurality on pset3, and so far I haven't edited any code, but whenever I try enter a vote it comes back as 'invalid vote'. Is this normal? And if so what should I do to solve this bit.
Connie's user avatar
  • 107
0 votes
1 answer
102 views

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

I wish I could be more specific with my question, but the problem is as the title suggests, check50's results do not seem to comport to mine. When I put it through check50, it fails on print_winner ...
BlueKhakis's user avatar
0 votes
1 answer
31 views

Plurality test passing on all except one

#include <cs50.h> #include <stdio.h> #include <string.h> // Max number of candidates #define MAX 9 // Candidates have name and vote count typedef struct { string name; int ...
JanQuadrantVincent's user avatar
0 votes
1 answer
1k views

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

I'm currently trying to do cs50 pset3 plurality problem and I have unfortunately ran into this error which I do not know how to overcome. The error is "non-void function does not return a value ...
Amos Ting's user avatar
0 votes
1 answer
99 views

Plurality - Why do I get segmentation fault?

I've tried running the program but when I put into an incorrect vote I get "segmentation fault". What's wrong? EDIT: I've changed: while (n < candidate_count) to while (n < ...
Alexander's user avatar
  • 145
0 votes
2 answers
115 views

check50 for plurality

Every example I try myself works perfectly fine but once I check50 it, I get error messages for not printing one,two, or all three winners. I saw some people having format issues with spaces, but I ...
maxilau's user avatar
0 votes
0 answers
52 views

Plurality works with my examples, but not with check50

I have finished my plurality program and its fine with the examples I give it, but it fails to print any of the winners of the Check50 examples. Any idea of how can I reproduce that elections, to see ...
Vladimir Briceño's user avatar
0 votes
0 answers
31 views

Fail to compile - PSET3/PLURALITY [duplicate]

I'm trying check my code using "check50 cs50/problems/2020/x/plurality" and the code fails to compile. The code seems working fine for me. Someone whould help? The error message: :) ...
Diniz's user avatar
  • 1
0 votes
1 answer
68 views

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

I've been working for weeks on pset3 - plurality, and all my logic is working fine in debug50, but not in real execution. It gives me either "segmentation fault" or (null). Basically, my ...
Vladimir Briceño's user avatar
0 votes
1 answer
728 views

pset3 plurality check50 invalid vote

So I have a few questions on Plurality check50 errors for this Pset: My Code is as follows: #include <cs50.h> #include <stdio.h> #include <string.h> #include <math.h> // Max ...
Pot Noodle's user avatar
0 votes
3 answers
80 views

Even though I get correct output check50 shows error in pset3 plurality problem

#include <cs50.h> #include <stdio.h> #include <string.h> // Max number of candidates #define MAX 9 // Candidates have name and vote count typedef struct { string name; int ...
Vidhi Shah's user avatar
0 votes
1 answer
173 views

Plurality Pset 3 I need Help

Whats wrong i keep getting segfault for(int o = 0; o < n - 1; o++) { if(candidates[o].votes > high0) { high0 = candidates[o].votes; name1 = candidates[o].name; } ...
iliketurtlz's user avatar
0 votes
1 answer
88 views

Pset3 Plurality returning "Invalid vote" in main programme code

When inputting vote names in "Plurality", the programme is returning Invalid vote. It looks like this in the terminal: ./plurality Alice Bob Garry Jim Number of votes: 4 Vote: Alice Invalid ...
 kittensyzygy's user avatar
0 votes
1 answer
64 views

Pset 3 Plurality Help (still not working)

When I compile my code it works, but when I try to run it, it says segmentation fault. I believe the segmentation fault is on the line that says printf("Winner is %s with %i votes\n", winner,...
Aarti's user avatar
  • 35
0 votes
1 answer
22 views

Prints " Invalid vote " for " code 1 " as vote function But works fine for " code 2 " as vote function. Whats wrong with " code 1 "?

// CODE 1 :- bool vote(string name) { // TODO for (int i = 0; i < candidate_count; i++) { if ( candidates[i].name == name ) { candidates[i].votes = candidates[i].votes + 1 ; return true ; } } ...
Shubham Thori's user avatar
0 votes
0 answers
45 views

Pset3 Plurality Help Again

This time I'm able to compile and run my code properly, but it tells me that there is a segmentation fault. Can someone help me figure out how to fix it? My code is below, thanks. #include <stdio.h&...
Aarti's user avatar
  • 35
1 vote
1 answer
267 views

Pset 3 Plurality Help

I was trying to compile my code for plurality but it says: plurality.c:82:1: error: control may reach end of non-void function [-Werror,-Wreturn-type] } ^ 1 error generated. <builtin>: recipe ...
Aarti's user avatar
  • 35
0 votes
1 answer
117 views

pset 3 plurality

To figure out the winner, I am trying to do a bubble sort and then print the last name (or names if the last two are tied). For some reason, after it goes through the first run-through of the bubble ...
Matthew's user avatar
  • 15
0 votes
2 answers
85 views

PSet 3 Plurality keeps getting 'segmentation fault'

This keeps coming up with "segmentation fault" when I run it although everything I want it do is working. It seems to be coming from the last if statement because there's no fault when I delete that ...
ssshhhkkk's user avatar
0 votes
2 answers
336 views

PSET3 Plurality Problem

void print_winner(void) { // TODO int c = 1; int numwin = 1; candidate mv[MAX]; mv[0].votes = -1; for(int i = 0; i < candidate_count; i++) { if(candidates[i].votes >...
user28696's user avatar
0 votes
2 answers
405 views

CS50 pset3 plurality program gives error for print_winner function (did not print both winners of election)

I have finished the plurality program for pset3 of cs50, but upon running check50 on my code, I receive the following error directed towards the print_winner function: :) plurality.c exists :) ...
qwert9988's user avatar
0 votes
1 answer
40 views

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

My program runs fine, but I have a question (it might be a silly one but I'm completely new at programming and just want to be sure I'm learning well!) string name = get_string("Vote: "); this is ...
mimi's user avatar
  • 5
1 vote
1 answer
178 views

pset3 plurality - trouble implementing a linear sort

I have some code that completely passes check50, but prints results way too many times. For instance, here's a typical output: ~/pset3/plurality/ $ ./plurality Alice Bob Carol Number of voters: 5 ...
dubflicker's user avatar
0 votes
1 answer
206 views

PSET3-Plurality. Check50 print winner Alice

My program behave correctly when i try it manually but it fails in check50. It returns " :( print_winner identifies Alice as winner of election " print_winner function did not print winner of election....
Aymene Cherradi's user avatar
0 votes
1 answer
135 views

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

For those who don't know, this pset is for calculating votes in an election. We were told to code the two functions vote and print_winner, and not to touch any of the other code. The program seems ...
Brandon Zemel's user avatar
0 votes
1 answer
205 views

Problem set 3 Plurality check50 error

I have managed to complete the plurality problem for problem set 3, however when I run check50 I get this one error: :( print_winner identifies Bob as winner of election print_winner function did not ...
ElektrikOx's user avatar