0

My functions codes git link

Here are my errors and my function codes in a git link (thanks folks for the feedbacks). I just don´t get what´s going on here, maybe i´m missing a detail, but it does work. Thank You enter image description here

2
  • 1
    Hi. Please edit your question as follows. Please remove screenshots of code and insert actual code via cut and paste. It is very tedious and difficult to read code that is in an image. It's impossible to transfer it to a test environment for testing and nobody wants to manually transcribe code. To quickly preserve code formatting, do this. While editing the question, highlight the code in the question and click on the quote symbols at the top of the entry window to identify the code as actual code and not simple text. Thanks.
    – Cliff B
    Feb 11 '20 at 7:22
  • Thanks for your feedback Feb 11 '20 at 23:36
1

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/pasted to gist.github.com, or pastebin.com, or similar, and provided a link.

  1. The number of candidates candidate_count could be anything from 1 to MAX_CANDIDATES. You need a loop to find the minimum number of votes, and use candidate_count instead of hard-coding the number of candidates.
  2. You cannot return more than one value from a function. The first return that gets executed leaves the function, code behind that return cannot be reached.
  3. eliminate does not need voter_count, as it operates on candidates only. It does need candidate_count. Not sure what you need two loops for.
  4. eliminate should not call is_tie (that's done in main). It should not check the existing eliminated status, and it should not, under no circumstances, un-eliminate a candidate by setting their eliminated status to false.
3
  • Thank you, i´m gonna try it now Feb 11 '20 at 23:40
  • I managed the eliminate function, but i still don´t get the find_min. I just don´t know how to compare the votes inside a loop, the only thing i can imagine is the loop constantly checking if the candidate "i" is still valid, but i´m stuck in how do i compare the remaining ones, using a loop? Feb 12 '20 at 3:06
  • Before the loop in find_min, declare an integer variable, the minimum so far. Initialise it to a number that you know is never less than the minimum, I would suggest voter_count (as no candidate should have more votes than that). Now whenever you find a non-eliminated candidate that has less votes, update this minimum-so-far. After the loop, you have the global minimum you are meant to return.
    – Blauelf
    Feb 12 '20 at 6:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .