I have this code:
When dx is larger than dy In the last line 'a' is always. In debug it acts like a is an Int. I don't get it.Code:int x,y;
long a=0,b=0,dx=0,dy=0;
dx=x1-x0;
dy=y1-y0;
a=dy/dx;
b=y0-a*x0;
Why?
Printable View
I have this code:
When dx is larger than dy In the last line 'a' is always. In debug it acts like a is an Int. I don't get it.Code:int x,y;
long a=0,b=0,dx=0,dy=0;
dx=x1-x0;
dy=y1-y0;
a=dy/dx;
b=y0-a*x0;
Why?
The code has undeclared variables.
What is x1? x0? y1? y0?
Second, you divide an integer type by an integer type, you get an integer result. Integer/intergral types include int, short, long, char, and the unsigned varieties of those. If you want floating point, then use float or double types.
Regards,
Paul McKenzie
I would also check if dx is non-zero before performing such a division:Quote:
Originally Posted by spikeyz