0

I have started runoff and just completed step 1 that is to write the vote function can someone tell me if it's correct? It seems to give the correct output but I don't think I used int rank in the right way. What I understand is in every iteration of the loop the Rank variable gets a new value but I don't really understand how that's of any help. I did this because I knew I had to track preferences and rank seemed the appropriate variable and now it seems to work but I don't understand what is happening after each loop.

This is my code

    bool vote(int voter, int rank, string name)
{
    int j = 0;
    for (int i = 0; i < voter_count; i++)
    if (strcmp(name, candidates[i].name) == 0)
    {
        rank = preferences[i][j];
        i++;
        return true;
    }
    return false;
}
2
  • 1
    In the vote function you are supposed to update the preferences array here you are not at all changing the values of the preferences array you are just assigning its value to rank which is just a local variable in the function which will no longer exist after you exit that function. – Ojou Nii Oct 16 '20 at 6:29
  • understood thanks :) @OjouNii – FoundABetterName Oct 16 '20 at 6:58

You must log in to answer this question.

Browse other questions tagged .