here cross multiplication is compared instead of division comparison
if ( ( points [ i ] [ 0 ] - points [ first ] [ 0 ] ) * ( points [ second ] [ 1 ] - points [ first ] [ 1 ] ) != ( points [ second ] [ 0 ] - points [ first ] [ 0 ] ) * ( points [ i ] [ 1 ] - points [ first ] [ 1 ] ) && minD > d ) { minD = d ; third = i ; } } cout << points [ first ] [ 0 ] << " , ▁ " << points [ first ] [ 1 ] << endl ; cout << points [ second ] [ 0 ] << " , ▁ " << points [ second ] [ 1 ] << endl ; cout << points [ third ] [ 0 ] << " , ▁ " << points [ third ] [ 1 ] << endl ; }