Questions tagged [plurality]

The tag has no usage guidance.

17 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
0
votes
0answers
8 views

CS50 pset 3 Plurality - Works until…Segmentation fault, and not enough vote prompts?

Task is to have people type in their votes for the candidates given in the command line, then the most voted candidate wins. I only need to and am allowed to write code for the last two function ...
0
votes
0answers
29 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
3answers
41 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
1answer
24 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
1answer
54 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,...
0
votes
1answer
14 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
0answers
39 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&...
0
votes
2answers
54 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
2answers
158 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
2answers
166 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
2answers
94 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 (...
0
votes
0answers
87 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
1answer
40 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
0answers
44 views

plurality questions

I am sure this is going to be the first of a couple of questions about this assignment. I also understand there are probably many problems with the code I am about to show but I do have two general ...
0
votes
1answer
139 views

pset3 I did print winner from pluarity, but check50 says I didn't. What's wrong?

I ran plurality according to spec and was able to print out all winners correctly. check50 says I didn't. What could be the problem? Is there any way to see what check50 used as inputs for plurality? ...
0
votes
2answers
383 views

Error testing in plurality question

I already test my code with all possible input and it working fine but when I run with check50 cs50/problems/2020/x/plurality, I got a couple of error result :( print_winner identifies Bob as ...
0
votes
1answer
149 views

Plurality - check50 issue

Hoping for some insight on this.. code works perfectly fine, prints correctly when testing in terminal, but for some reason check50 outputs errors once it starts printing winners. Would love to find ...