-
temperature
I have a problem
I have to convert temperature between farenhiet and celsius.
here is my code
Code:
#include <stdio.h>
int main ()
{
double temp;
int check;
printf("Please enter a fahrenheit temperature ");
check = scanf("%f", &temp);
if (check != 1)
{
printf("Invalid input\n");
return 0;
}
temp = (temp - 32.0) * 5.0 / 9.0;
printf("\nTemperature converted to celsius = %.1f\n", temp);
return 0;
}
my problem is that i get the wrong results. When i enter 5 i should be getting -15.0 but instead i get 1120.0. Can someone help me.
-
i found why the result stuffed up, i had to change the double to a float. Can any one tell me the difference between double and float? I always thought they were the same thing
-
here..
Code:
#include <stdio.h>
main()
{
float celcius, farenheit;
printf("Enter temp in Farenheit: ");
scanf("%f", &farenheit);
celcius = (farenheit - 32) * 5/9;
printf("Celcius: %f\n", celcius);
}
-
> Can any one tell me the difference between double and float?
Well it's important in the scanf
scanf( "%f", &float_var );
scanf( "%lf", &double_var );
doubles typically take up twice as much memory as floats, but they are a lot more precise, and have a greater range than floats.