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
8 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
6 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
14 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
17 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
44 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
13 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 ...
0
votes
1answer
33 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
29 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
17 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
27 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
15 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
79 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
40 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
26 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
24 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
26 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
53 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
34 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
51 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
38 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
39 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
32 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
35 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
26 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
50 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
29 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
66 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
22 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
29 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
48 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
42 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
101 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
139 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
39 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
43 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
36 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
211 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
74 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
49 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
60 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
28 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
148 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
79 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
77 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
19 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
38 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
60 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
17 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
47 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
117 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
2 3 4 5
25