Here is my code for the problem : Check If It Is a Straight Line
bool checkStraightLine(vector<vector<int>>& a) {
double m = (((double)a[1][1]-a[0][1])/(a[1][0]-a[0][0]));
for(int i=1;i<a.size()-1;i++)
{
double slope=(((double)a[i][1]-a[i+1][1])/(a[i][0]-a[i+1][0]));
if( m!=slope)
return false;
}
return true;
}
My doubt is why does my code produce an error when I replace :
double m = (((double)a[1][1]-a[0][1])/(a[1][0]-a[0][0]));
with
double m = (double)((a[1][1]-a[0][1])/(a[1][0]-a[0][0]));
and
double slope=(((double)a[i][1]-a[i+1][1])/(a[i][0]-a[i+1][0]));
with
double slope=(double)((a[i][1]-a[i+1][1])/(a[i][0]-a[i+1][0]));