More efficient way of counting the number of values within an interval?
What you want is a histogram of your values. If you want it to be flexible in the future with different bucket sizes, then you can use a std::vector and calculate how many buckets you need.

If the values are in range [0, 1] and 0 &lt; bucket_size &lt; 1, then the number of buckets you need obviously is ceil(1 / bucket_size).

So what I'd do would probably look something like this:

const float bucket_size = 0.05;
int number_of_buckets = (int)ceil(1 / bucket_size); // requires &lt;cmath&gt;
std::vector&lt;int&gt; histogram(number_of_buckets);

...

while (theFile &gt;&gt; area) {
    int bucket = (int)floor(area / bucket_size);
    histogram[bucket] += 1;
}


No big if-else cascade and easy to adjust for different bucket sizes.