# Thread: 'float' to 'double' conversion warning

1. ## 'float' to 'double' conversion warning

Pls help me solve this guys....
the code is as below:
Code:
```#include <stdio.h>
#include <math.h>

//#define A 90
//#define B 180
//#define C 360
#define PI 3.1416

void main(void)
{
char choice;
float voltage, current, totalPower, angle;

printf("\n=====");
printf("\nFinding the total power for different angles:");
printf("\nA. 90");
printf("\nB. 180");
printf("\nC. 360");
printf("\nD. Others");
printf("\nE. Quit");
scanf("%c", &choice);

switch(choice)
{
case 'A' :angle = 90;
printf("Enter the voltage(V):");
scanf("%f", &voltage);
printf("Enter the current(A):");
scanf("%f", &current);
totalPower =  voltage * current * cos((angle * PI) / 180);
printf("Total power = %.2fw\n", totalPower);
break;

case 'B' :angle = 180;
printf("Enter the voltage(V):");
scanf("%f", &voltage);
printf("Enter the current(A):");
scanf("%f", &current);
totalPower =  voltage * current * cos ((angle * PI) / 180);
printf("Total power = %.2fw\n", totalPower);
break;

case 'C' :angle = 360;
printf("Enter the voltage(V):");
scanf("%f", &voltage);
printf("Enter the current(A):");
scanf("%f", &current);
totalPower =  voltage * current * cos ((angle * PI) / 180);
printf("Total power = %.2fw\n", totalPower);

case 'D' :printf("Enter the angle:");
scanf("%f", &angle);
printf("Enter the voltage(V):");
scanf("%f", &voltage);
printf("Enter the current:");
scanf("%f", &current);
totalPower = voltage * current * cos ((angle * PI) / 180);
printf("Total power = %.2fw\n", totalPower);
break;

case 'E' :printf("Bye-Bye!\n");
break;

default :printf("Invalid Option!!\n");           //none of the above
break;
} //end switch

} //end main```
Code tags added by Kermi3 - Disabled smiles too

3. A float to double warning means that your program needs a cast somewhere. It's that simple. Or, if you want, you could ignore it. A float to double conversion can't really cause any harm.

4. #1 - Use code tags
#2 - Turn off smilies when you post code. The checkbox is right below where you type.
#3 - cos(x) returns a value of type double. When you are multiplying a float*double, the float is increased to the precision of a double for the operation. However, that's silly when you are storing the result in a float. So use this instead:

Code:
`(float)cos((angle * PI) / 180);`
Oh, and one more, completely off topic thing...200th post

5. Or you can use the appropriate math functions that return floating point precision ( cosf )

Code:
`totalPower = voltage * current * cosf ((angle * PI) / 180.0f);`
Notice when you have 180.0 that is really a double. You need to put the f afterwards to say you want it to be a float. You actually had 180 which would be an integer value.

6. For all the replies....thank u great people...
The solutions really meant a lot to me...
Ehmm...sorry for posting the message unpresentably...
It was my first message posting here...(' ,')