How to count array items within a numeric range
<p>I am tasked with trying to create a histogram from a set of sample values that a user provides.  I've created the part of the program that creates the array from sample value input, but now I must take a user input for the histogram. They give min value, max value, and number of bins.  So, I'm assuming the number of bins specifies the size of the array for the histogram.  But I'm stumped as to how I go to my other array and count how many values are in the specified range for a particular bin. I hope this makes sense.  Here is my code for the program thus far:</p>

<pre><code>#include &lt;iostream&gt;
using namespace std;


#define MAX_SAMPLES 100
#define MAX_BINS 20
#define DOUBLE_TOLERANCE 0.0000005
#define EXIT_VALUE -999
int promptUserAndGetChoice(); //function prototype for the menu

//for information describing sample set of data and functions that operated on //those data
class SamplingClass 
   {  
      private:
         char charID; //the user enters an id for his sample set
         int numbOfValues; // the number of good values the user enters
         double sampleValues[MAX_SAMPLES]; //for the set of sample values. 
                                           //max is 100
      public:
         bool readFromKeyboard(); //prototype function 
         bool printToScreen();//protype function

      SamplingClass(); //constructor

   };

      SamplingClass::SamplingClass() //initializing charID
       {
        charID = 0;
       }

bool SamplingClass::readFromKeyboard()
   {
      int i = 0;
      cout &lt;&lt; "Enter character identifier for this sample:";
      cin &gt;&gt; charID;
      cout &lt;&lt; "you entered " &lt;&lt;charID &lt;&lt; "\n";
      cout &lt;&lt; "Enter all samples, then enter -999 to end:\n";

     while (i &lt; MAX_SAMPLES)
      {
        cin &gt;&gt; sampleValues[i];     
   if 
      (sampleValues[i] &lt; EXIT_VALUE + DOUBLE_TOLERANCE &amp;&amp; sampleValues[i] &gt; EXIT_VALUE - DOUBLE_TOLERANCE)
      {
         break;

      }//End if/else

        i++;

       }//End while

   numbOfValues = i;    
    return true;

   }

//this function checks whether charID is empty and then performs accordingly
bool SamplingClass::printToScreen() 
   {
   if (numbOfValues == 0) ///either make a test for existance first or charID

      {
         cout &lt;&lt; "ERROR: Can not print uninitialized sampling!\n";
         return false;

      }  

   else 

      { 
         cout &lt;&lt; "Data stored for sampling with identifier " &lt;&lt; charID &lt;&lt; ":\n"; 
         cout &lt;&lt; "Total samples:" &lt;&lt; numbOfValues &lt;&lt; "\n";
         cout &lt;&lt; "Samples (5 samples per line):\n";
         int i;

         for(i=0; i&lt;numbOfValues;i++)
         {
         cout &lt;&lt; sampleValues[i] &lt;&lt; " ";

         if (((i+1) % 5) == 0)
          {  
             cout &lt;&lt; endl;
          }

         }
         cout &lt;&lt; endl;
        return true;

      }
    } 

class HistogramClass 
   {  
      private:
         double minBinValue; //specified by user
         double maxBinValue; // specified by user
         int numbBins; //specified by user, max of 10
         int histoBinCounts[MAX_BINS];

      public:
         bool setupHistogram(); //prototype function 
         bool addDataToHistogram(SamplingClass &amp;sampling);//protype function
         bool printHistogramCounts();
         bool displayHistogram(); 
   };

bool HistogramClass::setupHistogram()
   {
      cout &lt;&lt; "Enter minimum value:";
      cin &gt;&gt; minBinValue;
      cout &lt;&lt; "Enter maximum value:";
      cin &gt;&gt; maxBinValue;
      cout &lt;&lt; "Enter number of bins:";
      cin &gt;&gt; numbBins;
      cout &lt;&lt; "\n";
      if (numbBins &lt;= MAX_BINS) 
         {cin &gt;&gt; numbBins;}
      else
        cout &lt;&lt; "Sorry, the maximum amount of bins allowed is 20. Try again!\n";

    }



//function for the menu options that display to user  
int promptUserAndGetChoice()

   {
     cout &lt;&lt; "1. Enter a sample set of data values\n";
     cout &lt;&lt; "2. Print the contents of the current sample set\n";
     cout &lt;&lt; "3. Reset / Provide values for setting up a histogram\n";
     cout &lt;&lt; "4. Add the contents of current sample set to histogram\n";
     cout &lt;&lt; "5. Print bin counts contained in histogram\n";
     cout &lt;&lt; "6. View the histogram in graphical form\n";
     cout &lt;&lt; "0: Exit the program\n\n";
   }

int main()

{  
   const int enter_option = 1;
   const int printContents_option = 2;
   const int reset_option = 3;
   const int add_option = 4;
   const int printBin_option = 5;
   const int viewHist_option = 6;
   const int exit_option = 7;
   int menuChoice;
   SamplingClass sampleSet;
   HistogramClass histoSet;

   do 
      {
        promptUserAndGetChoice();
        cout &lt;&lt; "Your Choice: ";
        cin &gt;&gt; menuChoice;

   if (menuChoice == 1)
      {
       sampleSet.readFromKeyboard();
       cout &lt;&lt; "Last Operation Successful: YES\n\n";
      }
   else if (menuChoice == 2)

      {
      sampleSet.printToScreen();
      }

   else if (menuChoice == 3)
      {
      histoSet.setupHistogram();
      }

    } 
     while (menuChoice != 7);
     return 0;
}
</code></pre>
