Hot answers tagged

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 ...
user avatar
  • 20.7k
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 ...
user avatar
  • 930
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. // ...
user avatar
2 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
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; } } ...
user avatar
  • 418
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)...
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 ...
user avatar
  • 20.7k
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]....
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)...
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]...
user avatar
  • 131
1 vote
Accepted

pset 3: 2 problems in runoff pointed by check50

Working through your screenshots is annoying. It would be better if you posted just the relevant parts here in a code block (the {} button in the editor might help), or, if it's longer code, copy/...
user avatar
  • 20.7k
1 vote
Accepted

PSET3 Runoff - Tabulate

The int j = 0; would have to go into the loop, as you want to start at 0 for each voter. If you fix the other part and don't reset it, and j keeps growing, you might run into segmentation faults. So ...
user avatar
  • 20.7k
1 vote

RUNOFF PSET3 - bool is_tie(int min) function gives an error in Check50 unable to remove

The root of the problem: add a global variable called candidates_out to keep track of the number of eliminated candidates. From the spec: you should not modify anything else in plurality.c ...
user avatar
1 vote

RUNOFF PSET3 - bool is_tie(int min) function gives an error in Check50 unable to remove

There's no need to count the candidates having min votes. If all the remaining candidates have min votes, it's a tie. Any candidate having more votes than min will tell you it's not a tie (yet).
user avatar
  • 20.7k
1 vote
Accepted

vote function not able to assign getting error in runoff

candidates[i].votes is a case for the tabulate function, and should not be considered in vote, which is only meant to record a given vote. To determine the candidate with the name match, you would ...
user avatar
  • 20.7k
1 vote

PSET3 runoff 2020

The file name would likely be a typo :) It's ok to add header includes to runoff.c. I guess that sentence got refactored a bit, and the part in parentheses should be moved to the where-to-change part ...
user avatar
  • 20.7k
1 vote
Accepted

pset 3 runoff help again

Looking at the posted code and not sure of the full context of what you're trying to do, I'll take a run at it. This is more of a question of what to take out, not what to put in. The code is a for ...
user avatar
  • 63.1k
1 vote
Accepted

PSET3 Runoff Help Please

To check the name of the candidate in the 1st preferred coloumn only Remember, preferences[i][j]; Is simply, preferences[row][coloumn]; So, For first preference only preferences[changing_row][...
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 ...
user avatar
1 vote

PSET3 Runoff Help Please

Please share the code correctly so that I can help you as quickly as possible. Also tell a bit more about your problem Thanks.
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 ...
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) { ...
user avatar
1 vote

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 ...
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 ...
user avatar
  • 699
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.
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. ...
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 ...
user avatar
  • 699
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() ...
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 ...
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, ...
user avatar
  • 23

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