Skip to main content
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 (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
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

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
2 votes
Accepted

tabulate doesn't count votes when multiple candidates are eliminated

The problem is in this loop: for (int j = 1; j < candidate_count; j++) { if (candidates[preferences[i][j]].eliminated == false) { candidates[preferences[i][j]].votes += 1; } } ...
Chris's user avatar
  • 428
2 votes

Trouble with vote function

Just add one for loop and loop till the candidate_count If name and candidates[i].name matches then you should assign the i value to preferences[][] remember preferences[0][0] means that 1st voter has ...
Shehroz Ali's user avatar
2 votes
Accepted

PSET3 runoff 2020

1) Because I can't modify the header, how can I use strcmp (hints ask for) without string.h ? You can include string.h as per the spec: (and the inclusion of additional header files, if you’d like)...
DinoCoderSaurus's user avatar
2 votes
Accepted

Pset3 Runoff bool function

Did you watch the "functions" short in week 2? Doug mentions void at around 17:00 (the rest is also worth watching). void is a data type, just without any data. It's often used to indicate a lack of ...
Blauelf's user avatar
  • 21k
2 votes

Check50 all green but my own tests fail

Interesting that check50 doesn't pick that up! There is a problem in find_min. That function should have no side-effects, ie should not change any data, only report a result. This line candidates[j]....
DinoCoderSaurus's user avatar
2 votes

Runoff Help: Tabulate Handles Multiple Rounds of Preferences

modify your code to this void tabulate(void) { for (int i = 0; i < voter_count; i++) { for (int j = 0; j < candidate_count; j++) { if (candidates[preferences[...
duane gadama's user avatar
2 votes
Accepted

PSET3 Runoff Vote Function

/* The index of the candidate gives the information about the voter's choice. With the index known the voter's choice is also known. So basically, store the index i of the inner loop i.e. */ ...
devinder's user avatar
2 votes
Accepted

runoff bool is_tie

This is_tie function returns true as soon as it encounters the first candidate with min votes. It should return true when all non-eliminated candidates have min votes. If any candidate does not have ...
DinoCoderSaurus's user avatar
1 vote

PSET3 Runoff Help Please

vote This function inputs a string a search for the names in the table of candidates, it returns true once the name has been founded or matched i.e == 0 But how? Use for-loop to iterate through the ...
Shehroz Ali's user avatar
1 vote
Accepted

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

Actually your approach is very good to tabulate the vote count But, Have you noticed, that you only should have to update the vote count for the candidates that has been preferred first rank, and how ...
Shehroz Ali's user avatar
1 vote

Trouble with tabulate and printwinner

Just got tabulate to work with this code! void tabulate(void) { for (int k = 0; k < voter_count; k++) { if (candidates[preferences[k][0]].eliminated == false) { ...
getsendy's user avatar
1 vote
Accepted

Why does runoff not stop running?

The program "never finishes" because it is stuck in an infinite loop because there is never a winner. There's a problem in find_min, it always returns 0 because this if (candidates[i].votes < min)...
DinoCoderSaurus's user avatar
1 vote
Accepted

Pset3 Runoff tabulation issues

rank++ This means "tell me the value of rank, then add one to rank". So in the last line of elim_test, you're calling elim_test again with the exact same values over and over again. To fix ...
Llenk's user avatar
  • 744
1 vote

pset 3 runoff find_min - where is my logic failing ? - the check gives and error saying it doesn`t find the correct min

the function you wrote will return 0 back to the main function regardless of what values you've assign to other variables within the find_min function.
OutisMetis's user avatar
1 vote

Pset 3 Min function need some help

So I got the answer. My problem was the candidates[i].eliminated == false. Very easy to see, I don't know how I missed it. The candidates[i].eliminated == false should go with the first if function. ...
Dave's user avatar
  • 23
1 vote

pset3 print_winner (prints name when someone has a majority)

check50 is seeing if you print the candidate's name, then a newline. You're printing the candidate's name, then a space, then a newline. The formatting is pretty finicky, so you'll need to remove the ...
Llenk's user avatar
  • 744
1 vote

Pset3 Runoff - Printing All Candidates

Your is_tie function is returning true as soon as it finds atleast 1 candidate who has the minimum amount of votes. Instead, what it should do is it should spot all the candidates with the minimum ...
Sanket Pagadpalliwar's user avatar
1 vote

Printing to stdout? (PSET3, RUNOFF)

When in doubt, read the doc! From man printf Description The functions in the printf() family produce output according to a format as described below. The functions printf() and vprintf() ...
DinoCoderSaurus's user avatar
1 vote

PSET3 Runoff - tabulate() function for multiple eliminated candidates

I solved it myself with the debugger! There was a problem with the indices of my loops when going down one level of choice for a voter (i.e. when a first choice was an eliminated candidate). A ...
Xavier Villà Aguilar's user avatar
1 vote
Accepted

PSET3 Runoff check50 help

In the print_winner function when using printf function i didnt insert \n to print newline. Additionally, for the find_min function, i initialise min = candidates[0] votes which is not very correct, ...
Olivia's user avatar
  • 23
1 vote
Accepted

Vote returns false no matters what

The test condition must be true for the loop to run. Perhaps it should be n < candidate_count - 1;? If this answers your question, please click on the check mark to accept. Let's keep up on forum ...
Cliff B's user avatar
  • 69k
1 vote
Accepted

pset3 Runoff help

Thanks to seans help I was able to figure out the issue, here is my new code: bool vote(int voter, int rank, string name) { // iterates over candidates to see if name matches the name provided ...
ayeeitsalpha's user avatar
1 vote
Accepted

what is the significance of break; in tabulate function?

Each round counts one vote per voter, for their top preferred, non-eliminated candidate. Once that vote is counted, program moves on to the next voter. From the C99 standard section 6.8.6.3: A ...
DinoCoderSaurus's user avatar
1 vote
Accepted

i can't get the vote function in runoff right

vote receives a voter number, the currently processed rank, and a candidate's name. Since the first index to preferences is the voter number, and the second is the rank, you should use those. The ...
Blauelf's user avatar
  • 21k
1 vote

cs50 pset3 runoff tabulate

I was Encountering the same error and that was all due to a silly mistake we both have done. Have a Look here in the code void tabulate(void) { for (int v = 0; v < voter_count; v++) { ...
Siddhant Jha's user avatar
1 vote

cs50 pset3 runoff tabulate

How does this function returns the minimum votes and not the maximum votes? int find_min(void) { int min[1] = {0}; for ( int c = 0; c < candidate_count; c++) { if (candidates[c]...
AhWagih's user avatar
  • 141

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