# Ok I'm stuck with a double to float error

This is a discussion on Ok I'm stuck with a double to float error within the C Programming forums, part of the General Programming Boards category; Here's the snippet of code that I'm having problems with: Code: int customernumber; float waterlevel; float previouslevel; float totalwater; float ...

1. ## Ok I'm stuck with a double to float error

Here's the snippet of code that I'm having problems with:

Code:

int            customernumber;
float	waterlevel;
float	previouslevel;
float	totalwater;
float	totalbill;
float	amountowed;

printf("Enter customer number\n" );

scanf( "%d" ,  &customernumber );

printf("Enter current water level\n" );

scanf("%f" , &waterlevel );

printf("Enter previous water level\n" );

scanf("%f", &previouslevel );

totalwater = waterlevel - previouslevel;

totalbill = 30 + (totalwater/1000  * .55);

amountowed = totalbill;
I keep getting this warning "conversion from double to float, possible loss of data" for this line

totalbill = 30 + (totalwater/1000 * .55);

I dont understand what it could mean, everything is declared as float ( I, obviously, made sure of that), if anyone has any idea what's wrong with this line I would really appreciate it if ya could share it with me.
Thank you very much.

2. .55 by itself is a double constant.
Since the rest of the expression is float, I think it's this one which making the whole of the right hand side into a double expression.

So when you perform the assignment, the now double expression on the right is being converted to a float.

.55F is the way to define a float constant.

3. Or you could just add a cast:

Code:
totalbill = (float) (30 + (totalwater/1000 * .55));
[EDIT]
Or maybe declare everything as double and not as float.