Questions tagged [pset3]

The problem set for Week 3 asks students to write code for a classic puzzle game in the C programming language.

Filter by
Sorted by
Tagged with
0
votes
1answer
14 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
0answers
16 views

pset 3: i dont understand why runoff is not being ececuted?

#include <cs50.h> #include <stdio.h> #include <string.h> // Max voters and candidates #define MAX_VOTERS 100 #define MAX_CANDIDATES 9 // preferences[i][j] is jth preference for voter ...
0
votes
1answer
17 views

Trouble with find_min

I'm trying to implement a bubble sort in the find_min function in pset3 runoff. But It looks like it is not returning the correct min. I think it is because candidates[0].votes may not be the lowest ...
0
votes
0answers
17 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
1answer
22 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 ...
0
votes
2answers
15 views

PSET3 Plurality trouble. All of the checks on check50 work except 1!

I am having trouble figuring out what is wrong with my code. The only failure in check50 is (:( print_winner identifies Charlie as winner of election Cause print_winner function did not print winner ...
1
vote
5answers
37 views

Trouble with tabulate and printwinner

I'm having a hard time with the runoff problem in pset3, especially with the tabulate function. Based on the instructions it looks like I need to update the preferences array but I'm not sure how. I'm ...
0
votes
1answer
15 views

PSET3 strcmp error

I hate to ask again because this should be incredibly simple, but I'm literally running strcmp(name, candidates[j].name) and it is telling me candidates[j].name is an int in the error and not a char ...
0
votes
1answer
19 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 ...
1
vote
2answers
29 views

Trouble with vote function

I can't get the vote function in Runoff to work properly. Can anyone help explain what I am doing wrong here? bool vote(int voter, int rank, string name) { for (int i = 0; i < voter_count; i++) ...
0
votes
0answers
21 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
56 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 >...
1
vote
1answer
64 views

Logical flaw in Problem Set 3 - Tideman?

Whilst writing my code for Tideman in Problem Set 3, I had many problems with the lock pair function, as I am very new to coding. Some research I did online also showed that this question is ...
0
votes
1answer
29 views

sort_pairs function not working as per check50

This seems to be a common problem where the check50 program indicates a problem with the sort_pairs function. Here was my implementation of that function: int w; int l; int w1; int l1; for (int i=0; ...
0
votes
1answer
28 views

pset 3 runoff find_min - where is my logic failing ? - the check gives and error saying it doesn`t find the correct min

int find_min(void) { int min = voter_count; for (int i = 0; i < candidate_count; i++) { if (candidates[i].eliminated == false && candidates[i].votes < min) { min = ...
0
votes
0answers
33 views

Pset 3 runoff : I am getting{ :( runoff compiles code failed to compile}

I wrote my code but when I came to test it it gives me code failed to compile. I don't know why? :| here is my code include include include // Max number of candidates define MAX 9 // ...
0
votes
1answer
128 views

Please help about tideman lock_pair function!

// Lock pairs into the candidate graph in order, without creating cycles void lock_pairs(void) { for (int i = 0; i < pair_count; i++) { locked[pairs[i].winner][pairs[i].loser] = ...
0
votes
1answer
61 views

Program and debug50 different results

I'm trying to do pset3/tideman. My question is, why when I run program, I get different result (matrix[m]) than run with debug50? void lock_pairs(void) { for (int i = 0; i < pair_count; i++) ...
0
votes
1answer
45 views

Pset 3 Min function need some help

So my min code works, except it ignores the eliminate function. Can someone please show me where my logic is wrong? Thanks. int find_min(void) { int min = voter_count; int h = 0; for (int i = 0; i ...
1
vote
1answer
50 views

pset3 print_winner (prints name when someone has a majority)

I tried in two ways to show the winner of the election, and both testing manually are giving the correct result, but when testing by "check50" the message always appears: :( print_winner prints name ...
0
votes
1answer
22 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 ...
1
vote
0answers
109 views

Pset3 Tideman: lock_pairs skips middle pair if it creates a cycle

I'm having issues figuring out how to solve this problem without using recursion (I'm not sure how to solve things recursively). Its a program that determines the winner of a Tideman election and I'm ...
0
votes
0answers
58 views

pset3 tideman; can't pass check50 “lock_pairs skips final pair if it creates cycle”

I'm kind of confused about what the last pairs should be if it creates cycle. Like, if a->b, b->c, and the last pair is c->a, should I just skip it or turn it around, make it a->c? I tried both idea, ...
0
votes
1answer
62 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
1answer
16 views

What's in the bool function parenthesis?

hope everyone is staying safe. I just want to understand what's inside the parenthesis of the vote function in pset3 - Tideman: bool vote(int rank, string name, int ranks[]) What does it mean to ...
0
votes
1answer
29 views

p_set3 why does the int main clear the graph of locked in pairs?

hope everyone is staying safe. I am in week 3 and doing problem set # 3 - Tideman voting. In the main function it says the following: Why does it need to clear the graph of locked in pairs? (p.s. ...
0
votes
1answer
46 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
1answer
16 views

what does different return value signifies in this problem of runoff?

#include <cs50.h> #include <stdio.h> // Max voters and candidates #define MAX_VOTERS 100 #define MAX_CANDIDATES 9 // preferences[i][j] is jth preference for voter i int preferences[...
0
votes
1answer
39 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 ...
1
vote
1answer
58 views

Failing add_pairs function check50

I'm in the midst of working on tideman, in the midst of it i decide to check for the add_pairs function but i realised check50 is throwing me red coloured texts, solely based on add_pairs. I debugged ...
1
vote
5answers
88 views

check50 errors - runoff

I've been trying to resolve these myself for too long - I'm officially stuck These are the check50 errors I get: :( tabulate counts votes when multiple candidates are eliminated :( find_min ignores ...
0
votes
1answer
31 views

Back again with runoff problems, tabulate() passes no check50 tests

(I can't get formatting to work properly here so it might look a bit weird) void tabulate(void) { int j = 0; for(int i = 0; i < candidate_count; i++) { for( ; j < voter_count;) { ...
0
votes
1answer
69 views

Printing to stdout? (PSET3, RUNOFF)

In the specification for the print_winner function it says: If any candidate has more than half of the vote, their name should be printed to stdout and the function should return true. My solution ...
0
votes
1answer
25 views

PSET3 Best Practices for Speed in print_winner()

I'm trying to evaluate whether the method I'm using to find if a candidate has won the race has too much overhead. I'm certain there are other ways to do this, but below is the first that came to mind:...
0
votes
1answer
61 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
1answer
76 views

Tideman sort_pairs function

I tested this sort function separately and it sorts alright, but somehow doesn't pass the check50 test. The pairs.strength is the winning strength, recorded previously in add_pairs function. All my ...
1
vote
0answers
44 views

PSET3 - if(!vote(i, j, name)) {return 4}

I have a question regarding the reasoning behind If at any point, the ballot is deemed to be invalid, the program exits. from pset3. Why is this functionality included in runoff but not in plurality? ...
0
votes
2answers
53 views

Help with pset3 runoff

is this correct for vote function..struggled to figure out how to access candidate index so not sure if this is correct..any help/advice would be greatly appreciated bool vote(int voter, int rank, ...
0
votes
2answers
51 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
31 views

PSET 3 CS50x: Need help with print_winner

here's my print_winner code. Could someone help me see what's wrong? Thanks so much. void print_winner(void) { //dummy number. just so loser != 0 for later on. int loser = 90000; for (int ...
0
votes
1answer
13 views

Getting “control may reach end of non-void function” but I don't understand why

On problem set 3, I've defined a function like so: bool vote(string name) { for (int i = 0; i < candidate_count; i++) { if ((int) name == (int) candidates[i].name) { ...
0
votes
1answer
87 views

Tideman, my tests work but check50 says there is an error

When I test my code I get the correct output but check50 shows errors in print_winner function. :( print_winner prints winner of election when one candidate wins over all others print_winner did not ...
0
votes
0answers
39 views

pset3 tideman ranks array

In the tideman distribution code and the logic itself, the ranks[] array in the vote function is never actually sent outside the vote function. The array that's going to be passed into the ...
1
vote
1answer
20 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
1answer
78 views

PSET3 Runoff - tabulate() function for multiple eliminated candidates

I'm working on the tabulate() function, and to an extent the is_tie() function The tabulate() function passes all the tests of check50 but the last one: :( tabulate counts votes when multiple ...
0
votes
1answer
77 views

PSET3 Runoff check50 help

My code can compile and passes all the check50 except for this 2: 1) :( print_winner prints name when someone has a majority print_winner did not print winner of election 2) :( print_winner ...
0
votes
0answers
54 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
0answers
33 views

PSET3: More problems(weird loops and other unexpected results)

So I am still working on Runoff and I am having some weird results. It will return an obvious victory but any ties end up in weird loops and such. This has been apparent by adding printf functions ...
0
votes
1answer
39 views

Runoff pset 3, arrrays and indexing

I don't understand what's going on with the solutions to the voter preference and tabulate functions. I had set up a similar function to the answer with the exception that I had [voter][i] = rank; ...
0
votes
1answer
35 views

Vote returns false no matters what

bool vote(int voter, int rank, string name) { for(int n = 0; n == candidate_count - 1; n++) { if(strcmp(name, candidates[n].name) == 0) { n = preferences[voter][...

1
2 3 4 5
25