c++ - inf output computing line slopes -


i new @ c++.

i wrote code below supposed tell me if 2 lines have intersection point, figured 2 lines equal "m" in y=mx+b equation should not intersect , others would.

the program seems understanding this, unless slope of inputted line segment 0 outputs inf or -inf.

why happening?

#include <iostream> using namespace std; int main () { typedef double vector2d[2]; vector2d pointa, pointb, pointc, pointd; double lineseg1, lineseg2; double yes, no;   cout << "enter x point a: "; cin >> pointa[0]; cout << "enter y point a: "; cin >> pointa[1]; cout << "point = (" << pointa[0] << "," << pointa[1] << ")" << endl;  cout << "enter x point b: "; cin >> pointb[0]; cout << "enter y point b: "; cin >> pointb[1]; cout << "point b = (" << pointb[0] << "," << pointb[1] << ")" << endl;  cout << "enter x point c: "; cin >> pointc[0]; cout << "enter y point c: "; cin >> pointc[1]; cout << "point c = (" << pointc[0] << "," << pointc[1] << ")" << endl;  cout << "enter x point d: "; cin >> pointd[0]; cout << "enter y point d: "; cin >> pointd[1]; cout << "point d = (" << pointd[0] << "," << pointd[1] << ")" << endl;  lineseg1 = ((pointb[1]-pointa[1])/(pointb[0]-pointb[0])); cout << "slope segment 1 = (" << lineseg1 << endl;  lineseg2 = ((pointd[1]-pointc[1])/(pointd[0]-pointc[0])); cout << "slope segment 2 = (" << lineseg2 << endl;   if ( lineseg1 == lineseg2 ) {     cout << "no\n"; }  else ( lineseg1 != lineseg2 ) ;{     cout << "yes\n"; }  return 0;  } 

this line:

lineseg1 = ((pointb[1]-pointa[1])/(pointb[0]-pointb[0])); 

has divide 0 error.

i believe equation should be:

lineseg1 = ((pointb[1]-pointa[1])/(pointb[0]-pointa[0])); 

Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

python 3.x - PyQt5 - Signal : pyqtSignal no method connect -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)