|
发表于 2013-8-15 13:38:19
|
显示全部楼层
你循环加错位置~
引用楼上的楼上的代码 修改下:- #include<stdio.h>
- int Temperture(double a);
- const double MAD=1.8;//用double 不要用float 保持运算时类型一致
- const float GO=32.0;
- const double GLORY=273.16;//同上
- int main()
- {
- double b;
- printf("Please enter a value in Celsius:");
- while(scanf("%lf",&b) == 1)
- {
- Temperture(b);
- printf("Please enter a value in Celsius:");
- }
- return 0;
- }
- int Temperture(double a)
- {
- double c,d;
-
- //a=MAD*c+GO;//你这样是 把 1.8 * c(应为还没初始化是个垃圾值)+32.0 的值复制给a
- c = MAD*a+GO;//计算摄氏温度
- //d=a+GLORY;//a是垃圾值 d当然也是
- d = c + GLORY;//计算绝对温度
- //printf("%.2lf celsius is %.2lf fahrenheit,or %.2lf kelvin\n",a,c,d);
- printf("%.2lf华氏度 = %.2lf摄氏度 = %.2lf绝对温度\n",a, c, d);
- /*while(a>-273.15){
- printf("Please enter another value(q or any character to quit):");
- scanf("%lf",&a);*/
-
- return 0;
- }
复制代码 |
|