-
Temperature
Code:
#include <stdio.h>
void main (void)
{
int cel, fah;
printf("Temperature Conversion Program\n\n");
printf ("Enter the temperature in Faharenhiet:");
scanf ("%d", &fah);
cel = (fah-32.0)*5.0/9.0;
printf ("The Temperature in Celsius is %d\n\n");
}
Above program is written to convert the temprature in Faharenhiet to Celsius. When I run the program the conversion is not correct. What's wrong with the program? And If I want to show also Faharenhiet value at the end what do I have to write?
Thank You
-
There was something missing.
printf ("The Temperature in Celsius is %d\n\n",cel);
Also it is spelled Fahrenheit.
-
printf ("The Temperature in Celsius is %d\n\n");
You forgot about the format specifier, which will probabaly give you any spurious integer value the copmpiler decides on as the result.
printf ("The Temperature in Celsius is %d\n\n", cel);
-
Re: Temperature
Code:
#include <stdio.h>
int main(void)
{
int cel, fah;
printf("Temperature Conversion Program\n\n");
printf("Enter the temperature in Faharenhiet:");
scanf("%d", &fah);
cel = (fah-32.0)*5.0/9.0;
printf ("The Temperature in Celsius is %d\n\n", cel);
return 0;
}
-
You might also want to change the variables from int to float or double since it appears thats what you want.
-
You are using the int (integer) data types. It doesn't use decimals, and would just throw them away. Like you wouldn't be able to use 5.9, you would just have 5. And since you are using a fraction to convert it defeats the whole program, so change the int to long or double.