title: RUNOFF PSET3 - bool is_tie(int min) function gives an error in Check50 unable to remove
body: <p>I have tried a number of ways to execute the code in bool is_tie function; however, I always seem to receive the same error in check50.</p>
  
  <p>That said, I have run the program with the below function without any issues using the max candidates, 10 voters and with 7 eliminated candidates or 2, the program prints out the 2 tied candidates without issue. </p>
  
  <p>I have run the code through debug50 and it seems to work correctly by displaying the names of the tied candidates after eliminating two others; however, in the check50 tool the above error continues to come up.</p>
  
  <p>I have also used the printf function to display all of the values within the function and all of them seem to be correct as well.</p>
  
  <p>I have also used else {istie = false;} in the below is_tie function I am having an issue with; however, I receive the same error below as I get with the code also below the error.</p>
  
  <p>**:( is_tie detects tie after some candidates have been eliminated - is_tie did not return true **</p>
  
  <pre><code>bool is_tie(int min)
  {
      int ties = 0;
      bool istie = false;
      for (int i = 0; i &lt; candidate_count; i++)
      {
          if (candidates[i].votes == min &amp;&amp; candidates[i].eliminated == false)
          {
              ties++;
              int elim_cands = candidate_count - candidates_out;
  
              if (ties == candidate_count || ties == elim_cands)
              {
                  istie = true;
                  break;
              }
              else
              {
                  istie = false;
              }
  
          }
  
      }
      return istie;
  }
  </code></pre>
  
  <p>Similarily, I have been able to remove the error with this code immediately below; however, I only receive these two errors instead.</p>
  
  <p><strong>:( is_tie returns false when election is not tied<br>
  is_tie did not return false<br>
  :( is_tie returns false when only some of the candidates are tied<br>
  is_tie did not return false</strong>  </p>
  
  <pre><code> bool is_tie(int min)
  {
      int ties = 0;
      for (int i = 0; i &lt; candidate_count; i++)
      {
          if (candidates[i].votes == min &amp;&amp; candidates[i].eliminated == false)
          {
              ties++;
              return true;
          }
      }
      return false;
  }
  </code></pre>
  
  <p>If you have any ideas, please let me know what I can try. I have been working on this same error for the entire day and although the program works for me, I cannot submit it with the error.  Your ideas would be appreciated.</p>
  
  <p>All of the other functions are working correctly and the main code from the problem set is the same as originally provided. I did; however, add a global variable called candidates_out to keep track of the number of eliminated candidates.</p>
  
  <p><strong>HERE IS THE MAIN PROGRAM</strong> </p>
  
  <pre><code>#include &lt;cs50.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  
  // Max voters and candidates
  #define MAX_VOTERS 100
  #define MAX_CANDIDATES 9
  
  
  // preferences[i][j] is jth preference for voter i
  int preferences[MAX_VOTERS][MAX_CANDIDATES];
  // Candidates have name, vote count, eliminated status
  typedef struct
  {
      string name;
      int votes;
      bool eliminated;
  }
  candidate;
  
  // Array of candidates
  candidate candidates[MAX_CANDIDATES];
  
  // Numbers of voters and candidates
  int voter_count;
  int candidate_count;
  int candidates_out = 0;
  
  // Function prototypes
  bool vote(int voter, int rank, string name);
  void tabulate(void);
  bool print_winner(void);
  int find_min(void);
  bool is_tie(int min);
  void eliminate(int min);
  
  int main(int argc, string argv[])
  {
      // Check for invalid usage
      if (argc &lt; 2)
      {
          printf("Usage: runoff [candidate ...]\n");
          return 1;
      }
  
      // Populate array of candidates
      candidate_count = argc - 1;
      if (candidate_count &gt; MAX_CANDIDATES)
      {
          printf("Maximum number of candidates is %i\n", MAX_CANDIDATES);
          return 2;
      }
      for (int i = 0; i &lt; candidate_count; i++)
      {
          candidates[i].name = argv[i + 1];
          candidates[i].votes = 0;
          candidates[i].eliminated = false;
      }
  
      voter_count = get_int("Number of voters: ");
      if (voter_count &gt; MAX_VOTERS)
      {
          printf("Maximum number of voters is %i\n", MAX_VOTERS);
          return 3;
      }
  
      // Keep querying for votes
      for (int i = 0; i &lt; voter_count; i++)
      {
  
          // Query for each rank
          for (int j = 0; j &lt; candidate_count; j++)
          {
              string name = get_string("Rank %i: ", j + 1);
  
              // Record vote, unless it's invalid
              if (!vote(i, j, name))
              {
                  printf("Invalid vote.\n");
                  return 4;
              }
          }
  
          printf("\n");
      }
  
      // Keep holding runoffs until winner exists
      while (true)
      {
  
          // Calculate votes given remaining candidates
          tabulate();
  
          // Check if election has been won
          bool won = print_winner();
          if (won)
          {
              break;
          }
  
          // Eliminate last-place candidates
          int min = find_min();
          bool tie = is_tie(min);
  
          // If tie, everyone wins
          if (tie)
          {
              for (int i = 0; i &lt; candidate_count; i++)
              {
                  if (!candidates[i].eliminated)
                  {
                      printf("%s\n", candidates[i].name);
                  }
              }
              break;
          }
  
          // Eliminate anyone with minimum number of votes
          eliminate(min);
  
          // Reset vote counts back to zero
          for (int i = 0; i &lt; candidate_count; i++)
          {
              candidates[i].votes = 0;
          }
      }
      return 0;
  }
  </code></pre>
  
  <p>**SPOLER ALERT - BELOW IS THE CODE FOR FUNCTIONS RELATED TO PROGRAM:</p>
  
  <p>bool vote(int voter,int rank, string name) (void)tabulate(void) bool print_winner(void) bool is_tie(int min) int find_min(void) eliminate(int min)</p>
  
  <pre><code>   bool vote(int voter, int rank, string name)
     {
      for (int number = 0; number &lt; candidate_count; number++)
      {
          if (strcmp(name, candidates[number].name) == 0)
          {
              preferences[voter][rank] = number;
              return true;
          }
  
  
      }
      return false;
  }
  
      // Tabulate votes for non-eliminated candidates
      void tabulate(void)
  {
      for (int j = 0; j &lt; 1; j++)  //loop to record each voters rank 1
      {
          for (int i = 0; i &lt; voter_count; i++)
          {
              int number = preferences[i][j];
  
              if (candidates[number].eliminated == false) //if candidate is not eliminated, add 1 to candidates votes
              {
                  candidates[number].votes += 1;
                  j = 0;
              }
              else                                        //if candidate is eliminated, go to the same voters next preference
              {
                  i--;
                  j++;
              }
          }
  
      }
  }
  
  // Print the winner of the election, if there is one
  bool print_winner(void)
  {
      float majority = (float)voter_count / 2;
  
      for (int i = 0; i &lt; candidate_count; i++)
      {
          if (candidates[i].votes &gt; majority)
          {
              printf("%s\n", candidates[i].name);
              return true;
          }
      }
      return false;
  }
  
  // Return the minimum number of votes any remaining candidate has
  int find_min(void)
  {
      int min = candidates[0].votes;
      for (int i = 1; i &lt; candidate_count; i++)
      {
          if (min &gt; candidates[i].votes &amp;&amp; candidates[i].eliminated == false)
          {
              min = candidates[i].votes;
              int Position = i;
          }
      }
      return min;
  }
  
  
  // Eliminate the candidate (or candidiates) in last place
  void eliminate(int min)
  {
  
      for (int i = 0; i &lt; candidate_count; i++)
      {
          if (candidates[i].votes == min)
          {
              candidates[i].eliminated = true;
              candidates_out++;
          }
      }
  
  }
  </code></pre>