Questions tagged [plurality]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0 votes
1 answer
24 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 ...
0 votes
1 answer
8 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 ...
0 votes
1 answer
19 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, ...
0 votes
0 answers
10 views

How to select a different result in the same integer

Hey I don't really know how to ask my question, I will try to summarize. In candidates[i].votes I want to add a if to printf a specific things if I get two candidates the same results. In the base ...
  • 1
0 votes
1 answer
20 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 ...
0 votes
1 answer
67 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
85 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
43 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
32 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
21 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
122 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
163 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
319 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
49 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
44 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
68 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
206 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
59 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
22 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
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 ...
  • 14
0 votes
0 answers
75 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
120 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
91 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
20 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
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 ...
0 votes
1 answer
84 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
110 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
51 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
27 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
58 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
629 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
70 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
161 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
81 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
63 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
21 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
248 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
111 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
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 ...
0 votes
2 answers
307 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
391 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
39 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
171 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
171 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
119 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
192 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
150 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 (...