DevCPP assignment question

This is a discussion on DevCPP assignment question within the C++ Programming forums, part of the General Programming Boards category; Im having problems with compiler warnings. This is what i came up with to fix it. Code: double d_x, d_y; ...

  1. #1
    Registered User
    Join Date
    May 2002
    Posts
    31

    DevCPP assignment question

    Im having problems with compiler warnings. This is what i came up with to fix it.

    Code:
    double d_x, d_y;
    int i_z, i_a;
    
    d_x = d_y * (double) i_z;
    i_a = (int) d_x;
    Now this is fine ('cuase it works), but i wish i could use this next method and not get any warnings. Any ideas?

    Code:
    double d_x;
    int i_z, i_a;
    
    i_z = i_a * d_x;
    Oh the compiler warning is "assignment to int from double". Thanks.
    I never lie... except for right now.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,597
    I think the point is there is a typecast involved.
    Shouldnt be too difficult to accomodate with a few extra characters, as in your first example.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Mar 2004
    Posts
    12
    As per your second method, Why would you want to multiply a double by an int and save it to an int ? WOuldn't it be wiser to save it to a double ?
    Life is a piece of chocolates

  4. #4
    *******argv[] - hu? darksaidin's Avatar
    Join Date
    Jul 2003
    Posts
    314

    Re: DevCPP assignment question

    Code:
    double d_x;
    int i_z, i_a;
    
    i_z = int(i_a * d_x);
    Typecast it
    [code]

    your code here....

    [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. assignment operator question
    By l2u in forum C++ Programming
    Replies: 5
    Last Post: 12-17-2007, 08:48 AM
  2. array assignment question
    By threahdead in forum C Programming
    Replies: 2
    Last Post: 08-17-2003, 05:36 PM
  3. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  4. opengl DC question
    By SAMSAM in forum Game Programming
    Replies: 6
    Last Post: 02-26-2003, 08:22 PM
  5. Replies: 2
    Last Post: 12-17-2001, 05:40 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21