hello, i am working on a tempconverter program, i have tried a number of things to get this program to work and everytime i try something it seems to either mess something else up, or only do half of what i need it to do. could anyone give me some hints or insight as to what i am doing wrong? thanks
Code:
double fTOc(double); //Fahrenheit to Celsius
double cTOf(double); //Celsius to Fahrenheit
int main()
{
double temp;//temperature entered
char scale[1];//identify scale used (C or F)
double absZeroC = -273.15;//variable to easier identify absolute zero in Celsius
double absZeroF = -459.67;//variable to easier identify absolute zero in Fahrenheit
printf("Enter the temperature followed by F or C( Ex: \"75 F\"):");
scanf("%lf%s", &temp, scale);
if (scale == "C")
if (temp > absZeroC)
printf("\nTemperature in Fahrenheit is %f.\n", cTOf(temp));
else if ( temp < absZeroC)
printf("\nTemperature %f is less than absolute zero %f", temp, absZeroC);
if (scale == "F")
if (temp > absZeroF)
printf("\nTemperature in Celsius is %f.\n", fTOc(temp));
else if (temp < absZeroF)
printf("\nTemperature %f is less than absolute zero %f", temp, absZeroF);
else
printf("\nInvalid scale entry! Use C for Celsius or F for Fahrenheit!\n\n");
system("pause");
return 0;
}
double fTOc(double f)//fah to celsius
{
return (5.0 / 9.0) * (f - 32);
}
double cTOf(double c)//celsius to fah
{
return ((9.0 / 5.0) * c) + 32;
}