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 ...
4
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
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 ...
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.
// ...
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;
}
}
...
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 ...
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)...
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 ...
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]....
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. */
...
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)...
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][...
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 ...
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.
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 ...
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)
{
...
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 ...
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.
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. ...
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 ...
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 ...
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() ...
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 ...
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, ...
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 ...
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 ...
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 ...
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 ...
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]...
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/...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
runoff × 89pset3 × 72
cs50x × 19
tabulate × 11
check50 × 6
c × 6
error × 3
fails-check50-but-works × 3
help × 3
week3 × 3
print-winner × 3
is-tie × 3
functions × 2
2020 × 2
bool-is-tie × 2
cs50-ide × 1
check × 1
sort × 1
function × 1
cs50submit × 1
recursion × 1
for-loop × 1
make × 1
terminal × 1
cs50x2020 × 1