i have tried to write the code for implementing DDA algorithm for line drawing in turbo c++ 3.0.
but it is not running as some illegal operation has occured message appearing even though it complies without any error.
CODE
#include<iostream.h>
#include<graphics.h>
#include<conio.h>
#define ROUND(a) ((int)(a+0.5))
#include<math.h>
void main()
{
int x,y,x1,y1,x2,y2,m,gd,gm;
clrscr();
initgraph(&gd,&gm,"C:\\TC\\BGI");
cout<<"Enter Starting points";
cin>>x1>>y1;
cout<<"Enter Ending points";
cin>>x2>>y2;
int sign=(x2>x1)?1:-1;
m=(y2-y1)/(x2-x1);
x=x1;
y=y1;
putpixel(x,y,WHITE);
if(abs(m)<=1)
{
while(x<=x2||y<=y2)
{
x=x+sign*1;
y=y+sign*m;
putpixel(x,ROUND(y),WHITE);
}
}
else
{
while(x<=x2||y<=y2)
{
y=y+sign*1;
x=x+sign*(1/m);
putpixel(ROUND(x),y,WHITE);
}
}
getch();
closegraph();
}