In fact a better alternative to this would be using an epsilon constant to check whether the value of the product slope1*slope2 is "close enough" to -1, considering roundoff errors. Thus instead of just writing
I suggest you write the following
#include <math.h> // epsilon constant #define EPS 1E-6 ... if (fabs(slope1*slope2 + 1.0) < EPS) cout << "lines are perpendicular";
Login