Skip to main content
10 votes

Pset3: Plurality - Weird output!

You should rethink your logic for the print_winners function. Here's the pseudocode I'd use. Declare a maxvote int set to 0. Iterate over the list of candidates and check the number of votes. If ...
curiouskiwi's user avatar
  • 18.7k
6 votes
Accepted

Pset3 Helpers.c Frequency Not Working

For "A4", this returns 440 for me. Note that C's ^ operator is bitwise XOR, not power. Also, in C, 1/12 equals 0 (integer division truncates, you could avoid this by using floating point values like ...
Blauelf's user avatar
  • 21k
6 votes
Accepted

Pset3 Runoff - How to record name and rank in the Preferences Array?

Recall the definition of our preferences array: Next up is a two-dimensional array preferences. The array preferences[i] will represent all of the preferences for voter number i, and the integer ...
Blauelf's user avatar
  • 21k
5 votes

PSet3 Music Final check50 item

Found the answer: The variable that is passed into the Accidental condition must be a float not an int. float res = (hz * pow(2, x / 12)); NOT: int res = (hz * pow(2, x/12));
Jordan Maples's user avatar
5 votes

pset3 (runoff) keep getting print_winner error when using check50

All you have to do is add \n after %s. (No space in between). Thank @rassenguy
StrictHornet's user avatar
4 votes
Accepted

Pset3 Linear Search (control may reach end of non-void function)

The error message you're getting means the compiler isn't sure if the function will ever end (i.e. that there will be a return value under every possible eventuality). The problem lies in the first "...
ronga's user avatar
  • 1,415
4 votes
Accepted

pset3/find check50 frown helpers.c compiles. expected exit code 0, not 1

find.c and helpers.h cannot be altered. When check50 runs, it uses its own copies, so your alterations are lost. That will cause the compile to fail. You need to make all of your changes in ...
Cliff B's user avatar
  • 69.1k
4 votes
Accepted

What's wrong with this recover code?

A couple issues. First, the extra byte in the buffer (513 vs. 512) is not needed. The \0 is only necessary when working with strings and the end of string marker is needed. It works correctly because ...
Cliff B's user avatar
  • 69.1k
4 votes

pset 3 plurality help: not sure how vote function is implemented

vote(name) calls the function, passing the value of local variable name as the only argument. That value is then used to initialise name of vote (same variable name is no requirement, here "name" just ...
Blauelf's user avatar
  • 21k
4 votes
Accepted

PSET 3 Plurality - Program works but also returns invalid vote?

Pretty straightforward problem. Your vote function ALWAYS returns false, even after registering the vote. If false is returned to main, it'll print the invalid vote message. If vote() succeeds in ...
Cliff B's user avatar
  • 69.1k
4 votes
Accepted

PSET3 Tideman: Lock_Pairs Help

This is one of those times when I would recommend starting over. Try and break it down in terms of what you need your function to do, and build some pseudocode first. Some pointers: First, recursion ...
Sentox's user avatar
  • 950
3 votes
Accepted

Need help with recursive binary search

When you call a recursive function, you actually need to deal with the return value of that function. You are currently just calling BinarySearch(key, array, min, midpoint-1) for example and then ...
curiouskiwi's user avatar
  • 18.7k
3 votes
Accepted

How do I set a pointer to access the left half of an array? [PSET 3 - Binary search]

For a binary search, you keep only one range, not two. That one could be specified by either a pointer to the start of the range and a length, or a left and right index limiting the range (the version ...
Blauelf's user avatar
  • 21k
3 votes
Accepted

PSET 3: Game of fifteen. Everything in the board is equal to zero

You only need to delete this and the code will work: int board[d][d]; The reason is that the global variable board is declared above and can be used by any function int board[DIM_MAX][DIM_MAX]; ...
obesman's user avatar
  • 1,139
3 votes

A wierd error in won function (fifteen)

the hint is in 1-2-3|4-5-6|0-7-8 ie 1 2 3 4 5 6 0 7 8 Your won function will say that's a winning position, which it isn't. That same sort of scenario doesn't occur during the 4x4 gameplay. To ...
curiouskiwi's user avatar
  • 18.7k
3 votes
Accepted

Problem with pow() function, int frequency, helpers.c, pset3, music

(pow(2, index / 12) the issue is that both index and 12 are integers, so with integer division, the result will always be a whole number. Try using 12.0 instead of 12 to force a floating point ...
curiouskiwi's user avatar
  • 18.7k
3 votes
Accepted

pset3 duration itoa - with "&"

First, understand what strings in C are. Strings in C are pointers to a character, or char* (if you use type string, that's a custom alias for the same thing). The convention then says that the ...
Blauelf's user avatar
  • 21k
3 votes
Accepted

jpg's are not proper, mix of multiple images. Can anyone tell me whats wrong?"RECOVER"

EEK! A GOTO statement!!!! We'll come back to that. The second IF statement is bad. You can't simply replace every == with != to find the opposite condition of a complex logical test. If any of ...
Cliff B's user avatar
  • 69.1k
3 votes
Accepted

I can't figure out the problem in my resize (more) code

That line seems to be the culprit: for (int i = 0; i < f * outbi.biHeight; i++) Would have to use abs(outbi.biHeight) or equivalently (int) (f * HeightIn), not f * outbi.biHeight. The line fseek(...
Blauelf's user avatar
  • 21k
3 votes

Plurality is being failed by check50 when it works in my terminal (PSET3)

Resolved. I feel like a complete idiot. printf("%s \n", winner[i]); should be printf("%s\n", winner[i]);
wolv's user avatar
  • 31
3 votes
Accepted

Problem set 3 Plurality ISSUE cs50

If you fix the missing semicolon that @DinoCoderSaurus mentioned, this works fine. I suspect you hadn't compiled it after writing your function, so the default return false was still being used.
curiouskiwi's user avatar
  • 18.7k
3 votes

Problem Set 3 Runoff print_winner working, but I'm getting a Check50 error

check50 looks for an exact match of the candidate name. This printf format string "%s \n" "adds a little something".
DinoCoderSaurus's user avatar
3 votes

pset3, tideman, cs50 2020

add_pairs should increment pair_count. sort_pairs would access an element beyond the array length. If you have pair_count elements, you have pair_count-1 neighbour comparisons per round, one less ...
Blauelf's user avatar
  • 21k
3 votes
Accepted

Pset3: Tideman sort_pairs doesn't work?

preferences[pairs[i].winner][pairs[i].loser] > preferences[pairs[i+1].winner][pairs[i+1].loser] This condition swaps the elements in ascending order while check50 checks for the pairs array for ...
CSsucks's user avatar
  • 66
3 votes
Accepted

Program and debug50 different results

Declaring the array here int matrix[candidate_count]; allocates the memory for it. But it does not initialize the contents. At the end of the for loop, there is a good chance that matrix[m] has not ...
DinoCoderSaurus's user avatar
3 votes
Accepted

Plurality Pset 3 I need Help

Segfault is a memory error which is caused due to leakage in memory or aka bytes I need to see the whole code Remember you only need to print the name of the candidate(s) once it's vote matches the ...
Shehroz Ali's user avatar
3 votes

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

Instead of doing if(cycle[i]) do if(cycle(pairs[i].winner)). It should fix your problem because you are just calling a random iterator instead of the index of your respective candidate node. Also, ...
guy's user avatar
  • 31
3 votes
Accepted

PSET 3 Runoff Error: variable length array declaration not allowed at file scope

int voter_count, candidate_count; candidate candidates[candidate_count]; In C, you cannot define an array with a variable size at a global scope (even if you could, candidate_count does not have a ...
Sentox's user avatar
  • 950
3 votes
Accepted

cs50 plurality non-void function does not return a value in all control paths error

The error means a path that does not take the if branch or the else branch will not return a boolean, since the returns are embedded in those blocks. Think about this comment //if input name does not ...
DinoCoderSaurus's user avatar
3 votes
Accepted

Pset3 - runoff - print_winner and find_min error

You return prematurely. Simply finding a vote count smaller than the max is not enough. You need to keep going until you've looked at all the candidates, and then return the smallest vote count. // ...
Fuelled_By_Coffee's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible