Listing sales with a matching quantity Ive been sitting here for the past 20 minutes trying to make this simple/tiny function more 'readable' and 'clean'. Am I overthinking this or am I missing some major tips that could help me out?

string findSameSales (int numSold, int salesArray[], string namesArray[])
 {
  string ssList = " ";
  for (int counter = 0; counter &lt;= NUM_OF_POS; counter++)
    {
      if (numSold == salesArray[counter])
        {
         if (ssList == " ")
           ssList = namesArray[counter];
         else
           ssList += (", " + namesArray[counter]);
        }
      else;
    }

  return ssList;
 }
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".