Questions tagged [plurality]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0 votes
1 answer
38 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 <...
0 votes
1 answer
31 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 ...
  • 13
0 votes
0 answers
17 views

Week3 pset3 Plurality "print_winner function did not print all three winners of election"

Check50 passes all checks except for the very last one "print_winner function did not print all three winners of election" :) plurality.c exists :) plurality compiles :) vote returns true ...
0 votes
1 answer
15 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) =...
  • 17
0 votes
1 answer
14 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 <...
0 votes
1 answer
56 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 ...
0 votes
1 answer
98 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; } ...
0 votes
2 answers
212 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 <...
  • 5
0 votes
1 answer
45 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 ...
  • 5
0 votes
1 answer
33 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 ...
  • 101
0 votes
1 answer
53 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) ...
  • 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 ...
0 votes
0 answers
153 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&...
0 votes
1 answer
47 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 ...
0 votes
1 answer
21 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?
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 ?
0 votes
1 answer
16 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 ...
  • 14
0 votes
0 answers
60 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 ":( ...
0 votes
1 answer
86 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.
  • 107
0 votes
1 answer
79 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 ...
0 votes
1 answer
16 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 ...
0 votes
1 answer
865 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 ...
0 votes
1 answer
61 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 < ...
0 votes
2 answers
101 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 ...
0 votes
0 answers
46 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 ...
0 votes
0 answers
25 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: :) ...
  • 1
0 votes
1 answer
54 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 ...
0 votes
3 answers
553 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 ...
0 votes
3 answers
66 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 ...
0 votes
1 answer
149 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; } ...
0 votes
1 answer
62 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 ...
0 votes
1 answer
62 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,...
  • 25
0 votes
1 answer
20 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 ; } } ...
0 votes
0 answers
44 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&...
  • 25
1 vote
1 answer
231 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 ...
  • 25
0 votes
1 answer
105 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 ...
  • 15
0 votes
2 answers
83 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 ...
0 votes
2 answers
284 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 >...
0 votes
2 answers
371 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 :) ...
0 votes
1 answer
37 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 ...
  • 5
1 vote
1 answer
160 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 ...
0 votes
1 answer
143 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....
0 votes
1 answer
110 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 ...
0 votes
1 answer
178 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 ...
0 votes
2 answers
143 views

Why am I running into a segmentation error in PSET 3 plurality?

I've been working on plurality for hours now and I'm stuck with a "segmentaion error." So my approach to this problem was to sort the candidate objects in terms of votes and print the first object (...
1 vote
1 answer
52 views

Global Variable vs Local variables?

I'm trying to write a function that will be called in main(int argc, string argv[]) for pset 2: plurality. Inside the function, I want a for loop. I've written this: bool vote(string name) { ...
0 votes
1 answer
225 views

Having problems with plurality for cs50

I am trying to run the program for plurality for cs50, and the program compiles I put my candidates in and number of voters and vote, but instead of printing the winner it gives me a segmentation ...
  • 15
0 votes
0 answers
351 views

:( print_winner identifies Alice as winner of election. print_winner function did not print winner of election

What kind of test I should do to know What is the problem in my code because it's the only issue I have every other condition is working good.
0 votes
1 answer
50 views

My Plurality.c works when I test it with all of their usage examples but when I run check or submit it says it doesn't print

I'm a beginner and CS50 is the first coding experience I have. Like the title says, my code works when I test it but the CS50 won't accept it so I'm not sure what's wrong. Thanks for any help! ps. ...
0 votes
1 answer
208 views

Problem with plurality

when i check50 my code I get this message : :( print_winner identifies Bob as winner of election print_winner function did not print winner of election :( print_winner identifies Charlie as ...