0

Here's 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)
    {
        preferences[i][j] = candidates[i].name;
    }
    return false;
}

Now I know it's wrong as I can't store a string in preferences but I am not at all sure How to fix this or what variable to use? I have no clue on even what to think here I am totally stuck for a few days. Can someone please help and point out some additional resources because i think I won't be able to do this with only cs50 material

0

First of all, you have to loop through the candidates as you want to check if "name" ist a candidate's name. That means that you have to put candidate_count as the maximum in you for-loop.

You are right, you can't assign a string to the preference array. Insteady, you have to assign an integer as those represent the candidates. In this case you just have to assign "i" to the preference array as you are looping though the candidates array and "i" therefore stands for the current candidate.

You must log in to answer this question.

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