### Printing highest number in array.

Hi guys,
I'm writing a function that is suppose to print out the biggest number in the array.
I can get it to print it out, but then it prints at every loop. I only want it to print one time.
Where to put it in?

 ``1234567891011121314`` ``````void printMostEaten(int anArray[], int nSize) { for(int nStartIndex=0; nStartIndex < nSize; nStartIndex++) { // Highest index meet so far. int nHighestIndex = nStartIndex; // Search through every element starting from nStartIndex + 1. for(int nCurrentIndex = nStartIndex+1; nCurrentIndex < nSize; nCurrentIndex++) { if(anArray[nCurrentIndex] > anArray[nHighestIndex]) nHighestIndex = nCurrentIndex; } } }``````

Its because you have a loop inside a loop.

 ``123456789101112131415161718192021222324252627282930`` `````` #include using namespace std; int printMostEaten(int anArray[], int nSize); int main() { int result; int array[10] = { 1, 9, 12, 44, 21, 10, 11, 33, 55 }; result = printMostEaten(array, 10); cout << result; return 0; } int printMostEaten(int anArray[], int nSize) { int num = 0; for (int i = 0; i < nSize;i++) if (anArray[i] > num) num = anArray[i]; return num; } `````` `55`
Damn, much easier. Thank you very much.