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
1
vote
1answer
125 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
100 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
39 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
115 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
81 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
101 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
47 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
62 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
68 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
39 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
146 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
54 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
22 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
100 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
84 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
69 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
35 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
40 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
39 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][...
0
votes
1answer
151 views

PSET3 Runoff print winner not working

I am working on the print function for Runoff and I keep getting the response "The winner is: (null)" I guess at this point I can't tell if the tabulate function isn't working or if print isn't ...
0
votes
0answers
50 views

PSET3 Runoff — cannot seem to resolve “is_tie detects tie after some candidates have been eliminated”

I have been looking up and down through my code to no avail. Check50 shows that all tests are successful except for "is_tie detects tie after some candidates have been eliminated". I haven't the ...
0
votes
1answer
106 views

Pset3: Tideman sort_pairs doesn't work?

I know this has been asked before but I've checked every thread and couldn't find a solution. According to check50, my code for sort_pairs() doesn't work, and I can't figure out what could be wrong ...
0
votes
1answer
54 views

pset3 record_prefernces : i have segmentation fault error

i'm trying to implement record_preferences function but when i try to run the program it stops after getting first voter choices sorry for my messy thanks in advance the code :
0
votes
0answers
19 views

Can't compile runoff. it shows me error in { placement. could someone look into it please

#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 ...
0
votes
1answer
212 views

How do I implement lock_pair function correctly in Tideman?

Can anyone help check what is wrong with my logic? I tried implementing lock_pairs using these lines of codes: void lock_pairs(void) { // TODO int count = 0; for (int i = 0; i < ...
0
votes
2answers
229 views

CS50x 2020 Problem Set 3 Tideman

I have been working on the Tideman problem for a while now, and am still not able to find out how to implement the sort_pairs() function. I have implemented my sort_pairs() function, but it is not ...
-1
votes
1answer
69 views

CS50 Pset3 Tideman

please let me know what’s wrong with my work. Thank you!
0
votes
1answer
26 views

Problems executing make clang-7 error cs50

Hi, do you know how to solve this error? Thanks!!
0
votes
1answer
102 views

Problem with plurality

when i check50 my code I get this message : :( print_winner identifies Bob as winner of election print_winner function did not print winner of election :( print_winner identifies Charlie as ...
0
votes
1answer
46 views

Pset3: Plurality; Code doesn't consider command line arguments expect the first one!

I don't understand why my code only considers the first command line argument and shows "Invalid Input" for rest of the arguments upon passing other argument's name while voting. Here is the code ...
0
votes
1answer
74 views

pset3 tideman failed to compile

https://us-west-2.console.aws.amazon.com/cloud9/ide/393d9edee5b74d5abb364a24c01b987f?# I just finished the tideman problem, and everything works fine when I use it in the ide. However, when I run ...
0
votes
1answer
58 views

cs50 pset3 runoff tabulate - why you say candidates[i].votes = 0 ; here?

why use that ?? for (int i = 0; i < candidate_count; i++) { candidates[i].votes = 0; } } return 0;
0
votes
1answer
442 views

pset3 Runoff help

My code compiles but the only functions that had no errors are the print_winner and eliminate functions. I have tried to solve the errors for the other functions with no luck. My errors with the ...
0
votes
1answer
83 views

CS50 plurality will not return any answers

#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
189 views

tideman pset3 sort pairs - code doesn't work

I know it's not efficient. But I don't know why it doesn't work...:( void sort_pairs(void) { pair sorted_pairs[pair_count]; int strength[pair_count]; for (int k = 0; k < pair_count; k+...
0
votes
1answer
72 views

Pset3 Recover - need some help with my logic. Compiles but generates nothing

struggling as usual. I can't seem to figure out what I'm missing here. It compiles ok but when I run it nothing seems to happen. Any pointers to what I am missing? It is probably something looking ...
0
votes
1answer
149 views

why is this wrong?cs50 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 ...
0
votes
0answers
471 views

Tideman lock_pairs recursion problem

I'm currently working on Pset3 Tideman and am stuck on the recursion part of lock_pairs function. I tried implementing an additional function to check for a cycle, and obviously, it's not working. ...
0
votes
3answers
794 views

pset 3 plurality code help

My code prints all names in the case of a two way/threeway tie, but for some reason I still get an error message in check50 that it does not. The only thing I could think of was maybe it had to do ...
1
vote
0answers
101 views

Pset 3 Plurality - Error: linker command failed with exit code 1 (use -v to see invocation)

I have come across an unusual situation and I was not able to find a solution on this elsewhere. So for some reason, I was having issue compiling my plurality assignment and it kept on giving me the ...
0
votes
1answer
217 views

pset3 Tideman: function to print out preferences array is not working

I have written a function, print2d(), to print out a 2D array. I am using it to print out the preferences array after calling record_preferences() in main according to the provided template. The ...
0
votes
1answer
13 views

Resize Less - failing to resize small.bmp

Hi guys I've scratched my head about this for a week now and I'm struggling to see what the issue is. The smiley.bmp file seems to be resizing correctly but not the others. Can anyone offer some ...
0
votes
1answer
183 views

PSET3-Plurality. Check50 doesn't re

After finishing plurality, it fails check50. It returns "print_winner function did not print winner of election". In print_winner function I did the following void print_winner(void) { //create a ...
0
votes
1answer
121 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
0answers
61 views

Pset 3 Runnoff - Can't find the error

All, I have checked this every which way and can't figure out what I am doing wrong. If there is an outright winner ( candidate vote total > 50%) in the first round it works. In every other scenario ...
0
votes
0answers
423 views

PSET3 -Tideman - lock_pairs

I'm doing tideman and I can't understand where is the problem: my code seems to be working but the test says that it does not. I will share a bit of my code: int count = 1 void lock_pairs(void) { ...
0
votes
1answer
24 views

How does memory work with pointers and custom data structures

I am doing pset 3 tideman. For this I first implemented mergesort recursively. Then, to adjust it to the problem, I introduced a new part of the pair data structure, margin, and adjusted my mergesort ...
0
votes
1answer
61 views

Trouble modifying elements of an array of candidates in Plurality

I'm working on Plurality of pset3. I've run into an issue modifying the vote count of each candidate. I've isolated the problem in the full program below. It appears that candidate zero = candidates[...

1
2
3 4 5
25