title: How to calc percentage of coverage in an array of 1-100 using C++?
body: <p>This is for an assignment so I would appreciate no direct answers; rather, any logic help with my algorithms (or pointing out any logic flaws) would be incredibly helpful and appreciated!</p>
  <p>I have a program that receives &quot;n&quot; number of elements from the user to put into a single-dimensional array.
  The array uses random generated numbers.
  IE: If the user inputs 88, a list of 88 random numbers (each between 1 to 100) is generated).
  &quot;n&quot; has a max of 100.</p>
  <p>I must write 2 functions.</p>
  <p>Function #1:</p>
  <pre><code>Determine the percentage of numbers that appear in the array of &quot;n&quot; elements.
  So any duplicates would decrease the percentage.
  And any missing numbers would decrease the percentage.
  Thus if n = 75, then you have a maximum possible %age of 0.75 
  (this max %age decreases if there are duplicates)
      
  This function basically calls upon function #2. 
  
  FUNCTION HEADER(GIVEN) = &quot;double coverage (int array[], int n)&quot;
  </code></pre>
  <p>Function #2:</p>
  <pre><code>Using a linear search, search for the key (key being the current # in the list of 1 to 100, which should be from the loop in function #1), in the array.
      
  Return the position if that key is found in the array 
  (IE: if this is the loops 40th run, it will be at the variable &quot;39&quot;, 
  and will go through every instance of an element in the array 
  and if any element is equal to 39, all of those positions will be returned? 
  I believe that is what our prof is asking)
  
  Return -1 if the key is not found. 
  
  Given notes = &quot;Only function #1 calls function #2, 
  and does so to find out if a certain value (key) is found among the first n elements of the array.&quot;
  
  FUNCTION HEADER(GIVEN) = &quot;int search (int array[], int n, int key)&quot;
  </code></pre>
  <p><strong>What I really need help with is the logic for the algorithm.</strong></p>
  <p>I would appreciate any help with this as I would approach this problem completely differently than our professor wants us.</p>
  <p>My first thoughts would be to loop through function #1 for all variable keys of 1 through 100.
  And in that loop, go to the search function (function #2), in which a loop would go through every number in the array and add to a counter if a number was (1)a duplicate or (2) non-existent in the array. Then I would subtract that counter from 100. Thus if all numbers were included in the array except for the #40 and #41, and then #77 was a duplicate , the total percentage of coverage would be 100 - 3 = 97%.</p>
  <p>Although as I type this I think that may in of itself be flawed? ^ Because with a max of 100 elements in the array, if the only number missing was 99, then you would subtract 1 for having that number missing, and then if there was a duplicate you would subtract another 1, and thus your percentage of coverage would be (100-2) = 98, when clearly it ought to be 99.</p>
  <p>And this ^ is exactly why I would REALLY appreciate any logic help. :)</p>
  <p>I know I am having some problems approaching this logically.</p>
  <p>I think I can figure out the coding with a relative amount of ease; what I am struggling witht he most is the steps to take. So any pseudocode ideas would be amazing!</p>
  <p><em>(I can post my entire program code so far if necessary for anyone, just ask, but it is rather long as of now as I have many other functions performing other tasks in the program)</em></p>