Listing sales with a matching quantity
How about using std::accumulate():

Live Demo

#include &lt;string&gt;
#include &lt;iterator&gt;
#include &lt;algorithm&gt;
#include &lt;numeric&gt;

const int NUM_OF_POS = 10;

std::string findSameSales (int numSold, const int salesArray[], const std::string namesArray[]) 
{
    int index = -1;
    return std::accumulate(salesArray, salesArray + NUM_OF_POS, std::string(" "), [numSold, namesArray, &amp;index](std::string sales, int sold) { index++; return sold == numSold ? sales + " , " + namesArray[index] : sales; });
}


Alternative on more lines:

std::string findSameSales (int numSold, const int salesArray[], const std::string namesArray[]) 
{
    int index = -1;
    auto accumulator = [numSold, namesArray, &amp;index](std::string sales, int sold) 
    { 
        index++; 
        return sold == numSold ? sales + " , " + namesArray[index] : sales; 
    }
    return std::accumulate(salesArray, salesArray + NUM_OF_POS, std::string(" "), accumulator);
}


I really believe you should use STL algorithms for these kinds of things. Only roll your own loop etc. when you cannot use them. But this for example is almost the same as in the C++ reference docs so almost a "model case".