Divide By Zero error when slope is 0
<p>My code:</p>

<pre><code>#include "stdafx.h"
#include &lt;vector&gt;
#include &lt;iostream&gt;
#include &lt;algorithm&gt;
#include &lt;vector&gt;
using namespace std;
typedef pair&lt;int,int&gt; point;
int numTorres, numEdificios;
vector&lt;point&gt; towervec;
vector&lt;point&gt; skyvec;
typedef vector&lt;point&gt;::const_iterator tower_iter;
typedef vector&lt;point&gt;::const_iterator sky_iter;

int noofpaths = 0;

int findslope(const point &amp; i, const point &amp; j, const point &amp; k) {
    int dx, dy, dx1, dy1;
    dx = j.first - i.first;
    dy = j.second - i.second;

    int a = dy / dx;
    dx1 = k.first - i.first;
    dy1 = k.second - i.second;

    int b = dy1 / dx1;

    if(a != b) {


        int length1 = (j.first - i.first) * (j.first - i.first) + (j.second - i.second) * (j.second - i.second);
        int length2 = (k.first - i.first) * (k.first - i.first) + (k.second - i.second) * (k.second - i.second);
        if(length1 &lt; length2) {
            noofpaths++;
        }
    }
    return noofpaths;
}

int main() {
    int T;
    int n, m;
    cout &lt;&lt; "enter the test cases" &lt;&lt; endl;
    cin &gt;&gt; T;
    while(T--) {
        cout &lt;&lt; "towers and skyscrapers" &lt;&lt; endl;
        cin &gt;&gt; n &gt;&gt; m;


        for(int i = 0; i &lt; n; i++) {
            point p;
            cin &gt;&gt; p.first &gt;&gt; p.second;
            towervec.push_back(p);
            skyvec.push_back(p);

        }
        for(int i = 0; i &lt; m; i++) {
            point p;
            cin &gt;&gt; p.first &gt;&gt; p.second;
            skyvec.push_back(p);
        }



        for(tower_iter i = towervec.begin(); i != towervec.end(); i++) {
            for(tower_iter j = i + 1; j != towervec.end(); j++) {
                for(sky_iter k = skyvec.begin(); k != skyvec.end(); k++) {

                    int dx, dy;

                    noofpaths = findslope(*i, *j, *k);
                    cout &lt;&lt; noofpaths;
                }
            }
        }
    }
    return 0;
}
</code></pre>

<p>how to overcome the divide by zero error. if dx=0 or dy=0 or both are equal to zero the code breaks.</p>

<p>how to solve this error..for example take the points
i=-1,-1 j=1,-1, k-1 ,-1 . im tring to find if the 3 points are collinear. </p>
