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?

  • i tried to update preferences by using preferences[ranks[i][i+1]; still giving the same error –  Mannawar Hussain Jan 18 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. – Christopher Holder Jan 19 at 9:45
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. ;-)

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

You must log in to answer this question.

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