473,247 Members | 2,944 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,247 software developers and data experts.

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 4508
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

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

Similar topics

5
by: Jørgen Cederberg | last post by:
Hi, using Python 2.2.1 on Windows and QNX I'm having trouble understandig why int() raises a ValueError exception upon converting strings. >>> int('-10') -10 >>> int('10') 10 >>> int(10.1)
6
by: Gilles Rochefort | last post by:
Hello, I wrote the following code to wrap some existing C functions, and I get some warning about converting float to int. float zfactor; int tmp_x, corners_x; ...
171
by: Raman | last post by:
Hi All, Here is a small Code, int main(void) { char *p=(char *) malloc(100); strcpy(p,"Test1234567890"); p=p+10; free(p);
5
by: zfareed | last post by:
I created a program to determine the medians of arrays, be it of type int or float. I have used a template function and the problem I'm having is returning the float median for even arrays. Can...
92
by: Heinrich Pumpernickel | last post by:
what does this warning mean ? #include <stdio.h> int main() { long l = 100; printf("l is %li\n", l * 10L);
5
by: happytoday | last post by:
I compiled that program under turbo C without any problems but with sunstudi I found those errors: "pnt02ma1.c", line 37: warning: implicit function declaration: system "pnt02ma1.c", line 58:...
46
by: Kenny O'Clock | last post by:
This came up in a job interview, what is the output of the program below? I tried to compile and run it myself, but my compiler (lcc-win32) aborts with this errors.... Warning test2.c: 3 ...
2
by: Pranav | last post by:
template <class X> class Node{ : : }; template <class X> class Link { :
5
by: qwert7465 | last post by:
any help would be appreciated. here is my code: // Final Project #include <iostream.h> #include <iomanip.h> void checkout();
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.