Annoying problem
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Annoying problem

Hybrid View

  1. #1
    Join Date
    Jun 2012
    Posts
    1

    Annoying problem

    I have this code:
    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;
    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.
    Why?

  2. #2
    Join Date
    Apr 1999
    Posts
    27,422

    Re: Annoying problem

    Quote Originally Posted by spikeyz View Post
    I have this code:
    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;
    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.
    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

  3. #3
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,269

    Re: Annoying problem

    I would also check if dx is non-zero before performing such a division:
    Quote Originally Posted by spikeyz
    Code:
    a=dy/dx;
    Victor Nijegorodov

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center