468,513 Members | 1,597 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,513 developers. It's quick & easy.

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

2
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
Mar 15 '08 #1
2 4306
JosAH
11,448 Expert 8TB
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:

Expand|Select|Wrap|Line Numbers
  1. int nbsec = (int)(((s3 / caloriesstep) / s4) * s5) ;
  2.  
kind regards,

Jos
Mar 15 '08 #2
hili
2
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:

Expand|Select|Wrap|Line Numbers
  1. int nbsec = (int)(((s3 / caloriesstep) / s4) * s5) ;
  2.  
kind regards,

Jos

thanks alot for your heelp

regards
li
Mar 15 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

5 posts views Thread by Jørgen Cederberg | last post: by
6 posts views Thread by Gilles Rochefort | last post: by
5 posts views Thread by zfareed | last post: by
92 posts views Thread by Heinrich Pumpernickel | last post: by
5 posts views Thread by happytoday | last post: by
46 posts views Thread by Kenny O'Clock | last post: by
2 posts views Thread by Pranav | last post: by
1 post views Thread by fmendoza | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.