Assistace please
Assistace please
I need to Write a C++ program where you input the slopes for two lines and determine if the lines are are perpendicular to each other. I need to input the slopes from the screen.
so far i have this
#include <iostream> using namespace std; int main() { float slope1; float slope2; cout <<; "Please enter two slopes:" <<; endl; cin<< slope1 << slope2; cout << "You entered " << slope1 << " and " << slope2 << endl; return 0; }
18 Nov 06, 9:53AM
Remember that two lines were perpendicular if the product of their corresponding slopes equals -1. In other words all you need is an IF statement deciding whether
<div class="orangebox">[code]</div>
or not.
I hope this helps.
18 Nov 06, 11:02PM
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