Rich (BB code):
#include<stdio.h>
#include<ctype.h>
void work(void);
double fah_2_cels(double fahr );
double cels_2_fahr(double cels);
int main(void)
{
char more;
puts("\n This program for converting temperature from c to f and vice versa");
printf("\n--------------------------------------------------------------------\n");
do{
work();
puts("\n do you want to continue(Y/N)?");
scanf(" %c" ,&more);
}while(toupper(more)!='N');
return 0;
}
void work(void)
{
double temp,temp1,con;
char unit;
printf("enter the temperature value follwed by f for fehrenhuit and c for celisus\n ");
scanf("%lg",&temp1);
scanf("%c",&unit);
/* if(((temp1<=-459.67&&unit= 'f')||(temp1<=-459.67 &&unit='F')) || ((temp1<=-273.15 &&unit='c' )||(temp1<=-273.15 &&unit='C')))
{
con=-500;
printf("error -500 your temp is lower than absolute zero");
}*/
switch(toupper(unit))
{
case 'F':
temp=fah_2_cels(temp1);
printf("temperature in cel is %g C and in fehren is %g F" ,temp,temp1);
break;
case 'C':
temp=cels_2_fahr(temp1);
printf("temperature in fahr is %g F and in celisus is %g C",temp,temp1);
break;
default:
printf("You did enter wrong letter or you did not enter letter at all");
}
}//closes void work()
double fah_2_cels(double fahr)
{
return ((5.0/9.0)*(fahr-32.0));
}
double cels_2_fahr(double cels)
{
return ((9.0/5.0)*cels +32.0); //If you find that the results are off look at these functions
}
the user will enter temperature like 125f and the program read it and figure that it is fehrenheit and convert it to celisus
i write the code and it work but i need to ad condition if temp in feh. <=-459.67 or the cel<=-273.15 both function will return error so how can i do this
Last edited: