Does anybody have any ideas on how to find the largest number in an array, but keep the location it's stored in? For instance, I want to find the largest number in array "frequency[8]", and still know whether it's stored in "frequency[0]", "frequency[1]" and so on.
#include <iostream>
#include <algorithm>
usingnamespace std;
int main()
{
int frequency[8] = {1,2,3,10,5,6,7,-8};
int* p = max_element(frequency, frequency+8);
cout << "The largest number is " << *p
<< " and it is in frequency[" << (p - frequency) << "]\n";
}
Got it - also, since I'm still kind of a beginner, what's with the "*" symbol before variable p in line 6/7? Also, how would you suggest reading from that? I also need to then set the value of an integer to where the value of "frequency" is saved. (For example, I need to make integer "p1turn" where the highest number is stored - from the code sample above, that would be in "frequency[3]" so p1turn = 3.