what do i do with this? [Warning] converting to `int' from `float'

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hili
    New Member
    • Mar 2008
    • 2

    what do i do with this? [Warning] converting to `int' from `float'

    hello, im a starter in C++, for my assignment i have encountered the following warning which stops me from compiling, can any1 help please?
    any suggestion would be greatly appreciated.
    thanks alot

    ----> int nbsec = ((s3 / caloriesstep) / s4) * s5 ; <---
    [Warning] converting to `int' from `float'

    thanks!
    li
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Originally posted by hili
    hello, im a starter in C++, for my assignment i have encountered the following warning which stops me from compiling, can any1 help please?
    any suggestion would be greatly appreciated.
    thanks alot

    ----> int nbsec = ((s3 / caloriesstep) / s4) * s5 ; <---
    [Warning] converting to `int' from `float'

    thanks!
    li
    At least one of the values s3, s4, s5 and/or caloriesstep has type float. Therefore
    the type of the result of the expression is float. You want to assign that value to
    nbsec which is an int. You'll lose 'precision' when you do that. Explicitly cast
    the value back to type int to keep the compiler from warning you about it:

    [code=c]
    int nbsec = (int)(((s3 / caloriesstep) / s4) * s5) ;
    [/code]

    kind regards,

    Jos

    Comment

    • hili
      New Member
      • Mar 2008
      • 2

      #3
      Originally posted by JosAH
      At least one of the values s3, s4, s5 and/or caloriesstep has type float. Therefore
      the type of the result of the expression is float. You want to assign that value to
      nbsec which is an int. You'll lose 'precision' when you do that. Explicitly cast
      the value back to type int to keep the compiler from warning you about it:

      [code=c]
      int nbsec = (int)(((s3 / caloriesstep) / s4) * s5) ;
      [/code]

      kind regards,

      Jos

      thanks alot for your heelp

      regards
      li

      Comment

      Working...