You have to use the correct format specifier which will be scanf("%f",&f)
in this case.
Also fc=((5.0/9.0)*(f-32))
, otherwise integer division yields 0
.(Integer division truncates).5/9.0
will also work.
It is useless to put getch()
after return
statement. It will never reach upto that line.
What happens in your version?
Actually when two integers are divided the result is the quotient. If there any fractional part it is discarded. If you divide 5 by 9 the result will be 0.555...
. When fractional part discarded it will be 0
. So you always get 0
.
Whenever you need an outcome of a division not t truncate you must make one of them floating point. That ensures that it(result) will not truncate.
So the program would be
#include<stdio.h>
#include<stdlib.h>
void celciusToFahreinheit();
float fahr_temp,celc_temp;
int main()
{
celciusToFahreinheit();
return EXIT_SUCCESS;
}
void celciusToFahreinheit()
{
printf("\n Enter the temperature (in *F) to covert it into Celsius: ");
if( scanf("%f",&fahr_temp) != 1 ){
fprintf(stderr,"Error in input\n");
exit(EXIT_FAILURE);
}
celc_temp=((5.0/9.0)*(fahr_temp-32));
printf("\n %f*C",celc_temp);
}
Apart from the problem few things would be - Using readable function name and checking the return value of scanf
.