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
0answers
5 views

My program does **NOT** skip the last pair if it creates cycle. #PSET3 #Tideman

my program has apparently one bug. check50 says my program does NOT skip the last pair if it creates cycle. However, I ran my function through debug and it did skip the last pair and did not write ...
0
votes
0answers
20 views

tideman sort pairs not working

dont know why my function isn't working, i suspect the while loop triggers even when it shouldn't. void sort_pairs(void) { // TODO supair supairs[pair_count]; supair unSorted[pair_count]; ...
0
votes
1answer
19 views

How to swap elements in “struct” data type?

I am working on "tideman" from pset3 and stuck on sorting the data that i have in "struct" data type. Don't really know if it was supposed to be figured out on our own, but they ...
0
votes
0answers
17 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
0answers
11 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: :) ...
0
votes
0answers
26 views

CS50 tideman Lockpairs function (Doesn't skip the last pair?)

So in order to solve lockpairs function, I made a custom function that can detect a cycle (it would return true if it has a cycle, false if it doesn't). My custom functions logic is: Check each pair ...
0
votes
0answers
30 views

Could someone explain why this function for pset3/tideman isn't correct

So as seems to be the case with many people, I'm struggling a bit with tideman. My code scores full marks up until the point where the pairs become "locked." The code for my lock_pairs ...
0
votes
1answer
18 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
0answers
16 views

Tideman: linking pairs to candidates

and thanks for helping. I am confused with Tideman, and would love some enlightenment: I successfully sorted pairs, and can't figure out, in order to fill the bool locked, how to link the candidates ...
0
votes
1answer
28 views

Pset3 Runoff Find Min not Coded Properly - Can't Find Error

The way I have coded it, I believe my min should be set correctly, but when I try to run it, the check50 says it's wrong. I tested it by printing my min at various points in the code, and it is not ...
0
votes
0answers
38 views

lock_pairs skips final pair if it creates cycle

I have been working on the tideman problem from Problem Set 3. After multiple attempts, I have been able to pass all the required checks except one: "lock_pairs skips final pair if it creates ...
0
votes
1answer
42 views

My runoff problem doesn't pass check50

when I run check50 this is the message I get and I don't know what to fix :( tabulate counts votes when all candidates remain in election tabulate function did not produce correct vote totals :( ...
0
votes
0answers
32 views

Problem Set 3 - Tideman Lock Pairs

I am trying to solve the tideman problem for pset3. I have managed to get all parts of my code working apart from the the two parts which relate to checking whether cycles are created. :( lock_pairs ...
0
votes
0answers
22 views

Error in recursive cycle check function for pset3 tideman

I've implemented a recursive function to check for cycles and return a boolean based on if a cycle is found or not. Check50 only returns one error, and that is for "lock_pairs skips final pair if ...
0
votes
0answers
28 views

PSET 3 TIDEMAN Locked pairs Function

I am relatively new to the community so please forgive me should my question not be coherent enough. Ok so basically check 50 tells me that everything in my code is okay except for the locked pairs ...
0
votes
1answer
74 views

Pset 3 runoff. Votes not updating, trying to understand the code sequencing

Ok so im stuck on the tabulate funtion in runoff for pset3. The issue im having is that when i call to "printf" the candidates vote counts the votes still come out as 0. So i dont think the ...
0
votes
1answer
22 views

PSET3 Runoff specification (year 2020): Multiple eliminated candidates featuring in the next-preferred candidates list

In the pset3 Runoff specification (year 2020), every voter effectively votes for their top-preferred candidate who has not already been eliminated. If the top-preferred candidate has already been ...
1
vote
1answer
131 views

lock_pairs skips final pair if it creates cycle lock_pairs did not correctly lock all non-cyclical pairs

can anyone please help I got only one error which is:- lock_pairs skips final pair if it creates cycle lock_pairs did not correctly lock all non-cyclical pairs and this is my code bool hash_cycle(int ...
1
vote
1answer
56 views

pset3 runoff help -> 3 :( showing on check50

I'm getting the following fails when I check pset3 runoff (all the rest are coming up as correct) :( tabulate counts votes when multiple candidates are eliminated tabulate function did not produce ...
0
votes
0answers
24 views

Lock pairs and Recursivity

I've been trying to solve this pset since more than a month and don't want to give up... so this is the first time I'm coming to ask for help. Basically I separated in two parts the lock_pairs ...
0
votes
0answers
59 views

Can't get pset3/tideman's lock-pairs function to work

Before going to Python I thought I'd go back to some previous homework that I hadn't been able to solve - pset3/tideman. I've spent ages on this but I just can't seem to figure out the lock function. ...
0
votes
1answer
29 views

incompatible integer to pointer conversion passing 'int' to parameter of type 'const char *

bool vote(int voter, int rank, string name) { // TODO for(voter=0;voter<=voter_count;voter++) { for(rank=0;!strcmp(name, candidates[rank].name == 0);rank++) { preferences[voter][...
0
votes
3answers
101 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
1answer
73 views

pset3 Tideman: checking for cycles

I made it so that if a losing candidate in any pair wins in another, a function checks whether there's the losing candidate in that pair wins in any other, and so forth. this here is the unlocks the ...
0
votes
3answers
40 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 ...
1
vote
1answer
31 views

pset 3 runoff help again

I still dont know what to put in for loop :( I still dont know what to put in the for loop for(int k = 0; k < voter_count; k++) { for (int j = 0; j < candidate_count; j++) { ...
1
vote
3answers
34 views

PSET3 Runoff Help Please

for(m = 0; m < voter_count; m++) { for(t = 1; t < 4; t++) { string name = get_string("Rank %i: ", t); } printf("\n"); } } bool vote(int voter, int rank, string name) { ...
0
votes
1answer
84 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; } ...
1
vote
1answer
52 views

runoff tabulate error :( tabulate counts votes when multiple candidates are eliminated

void tabulate(void) { for (int i = 0; i < voter_count; i++) //as long as the number of total voters has not been met; this increases which voter we are on { int j = 0; ...
0
votes
1answer
71 views

My print_winner from pset3/tideman is doing everything right and still check50 says it's wrong

void print_winner(void) { bool looser; for (int i = 0; i < pair_count; i++) { looser = false; for (int j = 0; j < pair_count; j++) //checks if each winner ever lost ...
0
votes
1answer
44 views

Pset3 runoff tabulation error

[![enter image description here][1]][1] I keep getting a tabulation error with check50 that I cannot replicate 11 voters, 4 candidates, 3 or 4 rounds of voting works fine with I run it, and debug50 ...
0
votes
1answer
53 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
35 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
41 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
35 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
81 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
35 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
85 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
25 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
37 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
65 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
2answers
48 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
136 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
177 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
42 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
51 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
47 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 <cs50.h> #include <stdio.h> #include <string.h> // Max ...
0
votes
1answer
288 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
79 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
51 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
2 3 4 5
26