0

How to set rank for all preferences?, as in the specs, it is mentioned ranks[i] is the voters ith preferences

Any thoughts on that to set rank for all preferences?

2
  • i tried to update preferences by using preferences[ranks[i][i+1]; still giving the same error Jan 18, 2020 at 11:54
  • Please try to check the manual on how to post on this forum. it is very hard to read if you post a picture like that. try posting the code and a complete breakdown of your question.
    – Chris
    Jan 19, 2020 at 9:45

1 Answer 1

0

If you start adding notes to your code it will make it easer for others to understand.

So the basics of it are correct. You are iterating over all the candidates

Then there is an error, candidates[i] candidates is a data structure that is created at the begging of the code.

// Candidates have name, vote count, eliminated status
typedef struct
{
    string name;
    int votes;
    bool eliminated;
}
candidate; 

This means that if you want to call the name of candidate 1 you need to call candidates[0].name if you want to call his votes then you need to call candidates[0].votes etc.

Then to you actual question

How to set rank for all preferences?

Try rewatching the walkthrough a couple times.

preferences[MAX_VOTERS][MAX_CANDIDATES]

It preferences are marked as a double array that tracks the [voter] and the [rank].

The table in the walkthrough is a very good way to visualize what should be inscribed in the array.

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

2
  • Hi Chris! Noted, but this one is for tideman (bool vote function) Jan 19, 2020 at 11:05
  • Understood, I change your tag to reflect that. Sorry I could not be of more help
    – Chris
    Jan 19, 2020 at 11:08

You must log in to answer this question.

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