• Skip to main content
  • Skip to footer

CS50's Introduction to Computer Science on Edx: Supplementary resource

CS50 threads to aide as a supplementary resource

Objective of vote function

CS50 threads to aide as a supplementary resource › Forums › CS50’s Introduction to Computer Science by Harvard University on Edx › Week 3 › Objective of vote function

  • This topic is empty.
Log In Register Lost Password
Viewing 1 post (of 1 total)
  • Author
    Posts
  • March 10, 2023 at 6:21 am #1197
    admin
    Keymaster


      Copy Code
      Copied
      Use a different Browser

      // 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) == 0)
                 {
      
                  //NEED TO INCREMENT VOTES RECEIVED BY CANDIDATES BY 1 FOR RANKS[J]
                  preferences[rank] = preferences[rank] + 1;
                  printf("rank is %i", preferences[rank]);
                  return true;
                 }
             }
          return false;
      }

          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]

    • Author
      Posts
    Log In Register Lost Password
    Viewing 1 post (of 1 total)
    • You must be logged in to reply to this topic.
    Log In

    Log in / Register

    Initiative by Digital Splendid OPC Pvt. Ltd.