Edit: I appreciate the answers very much!
So imagine we have a struct like this
struct BadQuestion
{
float a;
float b;
} BadArray[10];
On a typical day float a
will look like following
{ 0, 152.52, 25.26, 5.166, 263.25, 256.256, 452.25, 0, 0, 0 }
Now I need to find the smallest value (5.166) and get the index of that in the array (which would be 3) because later I will need to extract float b
from BadArray[3]
.
I do not want to include the 0 values in the search, of course. And what I've tired is adding all non-0 values to a vector then use min_element
to get the lowest value of float a
. Problem is that I don't know how to get the index.
Current code
vector<float> temp;
int size = 0;
for (int i = 0; i < 10; i++)
{
if (BadArray[i].a != 0) {
temp.push_back(BadArray[i].a);
size++;
}
}
auto entity = min_element(temp.begin(), temp.end());