- This topic has 0 replies, 1 voice, and was last updated 2 years, 9 months ago by .
Viewing 1 post (of 1 total)
Viewing 1 post (of 1 total)
- You must be logged in to reply to this topic.
aiannum.com has rebranded as Progaiz.com
› Forums › CS50’s Introduction to Computer Science by Harvard University on Edx › Week 3: [Algorithms] – Linear Search, Binary Search, Bubble Sort, Selection Sort, Recursion, Merge Sort › Objective of vote function
[dm_code_snippet background=”yes” background-mobile=”yes” slim=”yes” line-numbers=”yes” bg-color=”#abb8c3″ theme=”dark” language=”clike” wrapped=”yes” height=”” copy-text=”Copy Code” copy-confirmed=”Copied”]
// Update ranks given a new vote
bool vote(int rank, string name, int ranks[])
{
// TODO
for (int i = 0; i < candidate_count; i++)
{
if (strcmp(name, candidates[i]) == 0)
{
//NEED TO INCREMENT VOTES RECEIVED BY CANDIDATES[I] BY 1 FOR RANKS[J]
preferences[i][rank] = preferences[i][rank] + 1;
printf("rank is %i", preferences[i][rank]);
return true;
}
}
return false;
}
[/dm_code_snippet] Not sure if I am moving in the right direction. By the above vote function, no. of votes for a particular rank getting incremented by 1. Is that the objective of the vote function?
Reply
CS50x – Ed Discussion (edstem.org)
[learn_press_profile]
