mardi 1 octobre 2019

Funcion returning an extra 0

I have this function which calculates distance between two point, everything works fine but I get an extra zero at the end.

My input:

2  3, 12 30, 40 50, 5  1, 12 10, 3  4
float bruteForce(vector< pair <float,float> >::const_iterator brute, vector< pair <float,float> >::const_iterator end, float m)
{
    float min = FLT_MAX;

    for (int i = 0; i < m; i++)  
    {
        for (int j = i+1; j < m; j++)  
        {
            if ( dist(brute[i].first, brute[i].second, brute[j].first, brute[j].second ) < min)  
            {
                min = dist(brute[i].first, brute[i].second, brute[j].first, brute[j].second); 
                cout << min << endl; 
            }
        }
    }

    return min;
}


output:

1.41421, 
11.4018, 
34.4093, 
0

Aucun commentaire:

Enregistrer un commentaire