Code:
public int getObjectsAtSameDistance()
{
int ObjectsSameDistance;
// Scan thru array and see how many objs are at the same distance
for (int j = 0, j < 2, j++)
{
for (int i = j + 1, i < 2, i++)
{
if (distances[j] == distances[i])
{
objectsSameDistance ++;
break;
}
}
}
if (objectsSameDistance > 0)
objectsSameDistance ++;
return objectsSameDistance;
}
There is actually a problem with this method the more I think about it. Works fine for 3 elements / variables, but what if there's say 5, whereas 3 of them = 100 and the other 2 = 50 -- which ones do we report as being the same? As is the code will return a value of 5.
The solution is limited but not flawed ...
Trent Jackson
Bookmarks