Questions tagged [pset3]

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

302 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
0
votes
0answers
89 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
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
77 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
47 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
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
0answers
36 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
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
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 ...
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
0answers
51 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
334 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
0answers
98 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
19 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
45 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
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
43 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
0answers
72 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 ...
0
votes
1answer
139 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
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
0answers
36 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
49 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
63 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
60 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
20 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
33 views

Problems executing make clang-7 error cs50

Hi, do you know how to solve this error? Thanks!!
0
votes
1answer
62 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
298 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
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
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
500 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
0answers
343 views

Runoff - is_tie

Well I wrote my code and I don't know I am really stuck here with my code and can't get my head around it. Check50 returns only this error: :( is_tie detects tie after some candidates have been ...
0
votes
0answers
2k views

lock_pairs skips middle pair if it creates a cycle

I am doing tideman and I can't find the source of this error.below are my code=> bool isCircle(int from,int edgevalue,int paircount){ for(int i=0;i<paircount;i++) { if(pairs[i]....
0
votes
1answer
407 views

pset3: code failed to compile

Now I am doing tideman and I already test and all are working well and get the expected result.but when I check with Check50,I got this msg :( tideman compiles code failed to compile I just ...
0
votes
1answer
151 views

Pset 3 runoff Randomly Increasing Votecount

I'm close to solving pset 3 runoff but I've run into this interesting problem in my tabulate function. Whenever I run the program with the debugger, my vote counts keep increasing by very large ...
0
votes
1answer
229 views

pset3 (runoff) check50 is giving an error for print_winner

I can't find what's wrong with my code but check50 keeps telling me :( print_winner prints name when someone has a majority print_winner did not print winner of election :( print_winner returns ...
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 ...
0
votes
1answer
121 views

How to set rank for all preferences?

Any thoughts on that to set rank for all preferences?
0
votes
0answers
36 views

Pset3 Resize more- Random colours

Absolutely lost on this, checked the header and its correct but when I look at the resulting image from my code its just a bunch of random colors. Also, i'm trying to use the nearest neighbor ...
0
votes
0answers
21 views

pset3 resize more comfortable stuck for scaling down

Been spending a few days tackling scaling down the image. Below is my code. Can anyone help point me towards the right direction or find errors in my code? // Copies a BMP file #include <stdio.h&...
0
votes
0answers
12 views

pset3 Resize - How to do vertical scaling by copying the outfile?

Recopy method I'm using an array of data type BYTE to copy lines in outfile and paste them back, allowing me to do vertical scaling in the most efficient manner. However, this method causes garbage ...
0
votes
1answer
51 views

PSET 3 still stuck

I'm still so very stuck on this one. Below I have a cobbled together "solution" that at least increases the size of the image. I have no clue what I'm doing when it comes to copying the value of ...
0
votes
1answer
37 views

Segmentation fault on PSET3 recover

My program compiles, but wherever it runs I recieve a segmentation fault error. However i cannot see where the source of the problem is: #include <stdio.h> #include <stdlib.h> #include &...
0
votes
0answers
13 views

Why I am getting blank verdict on whodunit?

// Copies a BMP file ​ include include ​ include "bmp.h" ​ int main(int argc, char *argv[]) { // ensure proper usage if (argc != 3) { printf("Usage: copy infile outfile\n"); ...
0
votes
1answer
26 views

PSET 3 recover I can't open pointers. Always returns a NULL value

Whenever I try to run this code, it returns "could not open file", which means that jptr is assigned a null value. I don't know how to get rid of this, tried so many solutions. It keeps on happening ...
0
votes
1answer
33 views

PSET 3: Color is messed up

I can't figure out how to fix the colors of large.bmp when I run it. It resizes correctly but the pixels are all messed up and don't look like the original. Someone help me? Please and thank you! // ...
0
votes
1answer
1k views

Pset3: Tideman - sort_pairs error!

I have difficulty to understand what should the output of the function sort_pairs() should be!, What I understand is I should take the unsorted pairs[] and sort it. For example, this is pairs[] ...
0
votes
1answer
92 views

CS50 Recover.c | No idea what and where i'm going wrong | Can't debug or compile in CS50 IDE

I'm trying to debug in CS50 IDE but I'm continuously receiving this error; debug50: recover: No such file. and if I try to compile it says this "make: *** No rule to make target 'recover'. Stop." ...
0
votes
0answers
17 views

debugger only check the first breakpoint then jump to the end of code

I have tried many times , the debugger can only check the first if statement and it can be step over in the first if statement. But When it finished the if statement, just jump to the end of code, ...
0
votes
1answer
34 views

resize.c write to array

I think i made a breakthrough in this one with the rewrite method but i need to know how to write the triple to the array i tried a couple of things but didn't work out here's my code : int main(int ...

1
2
3 4 5
7