If you want to work with the STL, you can use the count function defined in the algorithm header.
Code:
#include <algorithm>
#include <iostream>
int array[10] = { 2, 5, 7, 2, 6, 5, 4, 3, 2, 5 };
int value;
std::cout << "Enter a value to search for: ";
std::cin >> value;
std::cout << "The value " << value << " exists "
<< std::count(array,array+10,value) << " times." << std::endl;
Possible output:
Code:
Enter a value to search for: 5
The value 5 exists 3 times.
If not, I would maybe suggest your find_match function be modified to return the number of times the item to be searched for is found. From your code example you don't really appear to need the location (index) of the array where the value to be searched for is found. Your code could therefore be rewritten somewhat such that this:
Code:
location = find_match(inCode, code, count);
if(location < MAXSIZE)
{
cout << "Code: " << total << " "<< code[location] << endl;
}
else
cout << "Code not found\n";
Can be made to look like:
Code:
int num = find_match(inCode, code, count);
if( num )
// If match was found, we already know the value equals inCode, we don't need
// to output code[location] to display that value, saves a bit of typing
cout << "Code: " << num << " "<< inCode << endl;
else
cout << "Code not found\n";