开发者

Program to Convert Fahrenheit to Celsius

I'm trying to convert temperature given in Fahrenheit to Celsius. But for some reason its not working properly. I know that a similar question has been asked but my problem is different because I can't even printout what I have scanned (using scanf) from the user.

Code:

#include<stdio.h>
#include<开发者_如何转开发;conio.h>

void main()
{
 float Fahrenheit, Celsius;

 clrscr();

 printf("Enter Temperature in Fahrenheit \n");
 scanf("%f",&Fahrenheit);

 Celsius = 5.0/9.0 * (Fahrenheit-32);

 printf("\n Temperature in Fahrenheit = %f", Fahrenheit);
 printf("\n Temperature in Celsius = %f", Celsius);

 getch();
}

Output :

Program to Convert Fahrenheit to Celsius

I'm using Windows 7 - 64 bit. IDE = Emulated C++ 3.0


I'm not sure (because your compiler might behave differently) but perhaps it's caused by this:

You're using 5.0 and 9.0 which are double values as well as 32 which is an int.

Try changing them to 5.0f, 9.0f and 32.0f.


It seems to be a compiler issue. My compiler (Emulated Turbo C++ 3.0) was not able to save my edits properly. So I went to C:\TC\Bin\ filename.c and opened the file in Notepad. Corrected the errors and compiled it again.

Now it works :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜