请帮忙运行一下这段C代码,请教一下为什么会出现这种现象,帮忙分析一下缺陷

/*编写一个程序,该程序要求用户输入一个华氏温度。程序以double类型读入温度值,并将它作为一个参数传递给用户提供的函数Temperatures()。该函数将计算相应的摄氏温度和绝对温度,并以小数点右边有两位数字的精度显示这三种温度。它应该用每个值所代表的温度刻度来标识这3个值。下面是将华氏温度转换成摄氏温度的方程: 通常用在科学上的绝对温度的刻度是0代表绝对零,是可能温度的下界。下面是将摄氏温度转换为绝对温度的方程: Kelvin=Celsius+273.16 Temperatures()函数使用const来创建代表该转换里的3个常量的符号。main()函数将使用一个循环来允许用户重复地输入温度,当用户输入q或其他非数字值时,循环结束。
*/
#include

void Temperature (double fah);
int main(void)
{
double fah;

printf("Please input an fahrenheit temperature\n");

while (scanf("%f",&fah)==1)
{   
    Temperature(fah);
    printf("Please input an fahrenheit temperature\n");
}
return 0;

}
void Temperature (double fah)
{
const float FAH_CEL_1=1.8,FAH_CEL_2=32.0,CEL_KEL=273.16;

printf("Fahrenheit = %.2f\n",fah);   
printf("Celsius = %.2f\n",fah*FAH_CEL_1+FAH_CEL_2);  
printf("Kelvin = %.2f\n",fah*FAH_CEL_1+FAH_CEL_2+CEL_KEL);

}
/*我的运行结果:
Please input an fahrenheit temperature
123.3
Fahrenheit = 0.00
Celsius = 32.00
Kelvin = 305.16
Please input an fahrenheit temperature
123.2
Fahrenheit = 0.00
Celsius = 32.00
Kelvin = 305.16
Please input an fahrenheit temperature

所有结果都是一样的,无论输入什么值
*/

#include "stdafx.h"
#include
#include

void Temperature (double fah);

int main(int argc, char* argv[])
{
double fah;

while (1)

{

 printf("Please input an fahrenheit temperature\n"); 

 char  szBuf[255]="";

 scanf("%s",szBuf);

 char *pTemp =szBuf;

 if(NULL!=pTemp)
 {

     while(*pTemp!='\0')
     {

       if(*pTemp!='.'&&(*pTemp>'9'||*pTemp<'0'))
       {
           printf("循环结束!\n");
           exit(0);

       }

       pTemp++;

     }

 }

  pTemp =szBuf;
  fah =atof(pTemp);
  Temperature(fah);

}

return 0;

}

void Temperature (double fah)
{

const float FAH_CEL_1=1.8,FAH_CEL_2=32.0,CEL_KEL=273.16;

printf("Fahrenheit = %.2f\n",fah);

printf("Celsius = %.2f\n",fah*FAH_CEL_1+FAH_CEL_2);

printf("Kelvin = %.2f\n",fah*FAH_CEL_1+FAH_CEL_2+CEL_KEL);
}

你将参数fah定义为double,但是在指定scanf的格式时用的却是“%f”,实际上double对应的格式符应该是"%lf"。

我在自己机器上把参数类型double改为了float编译了一下,运行正常(不过感觉你把换算公式搞反了,这里就不改了):

 #include <stdio.h>

void Temperature(float fah);

int main(){
        float fah;
        printf("Please input an fahrenheit temperature\n:");
        while(scanf("%f",&fah)==1){
                Temperature(fah);
                printf("Please input an fahrenheit temperature\n:");
        }
return 0;
}

void Temperature(float fah){
        const float FAH_CEL_1=1.8,FAH_CEL_2=32.0,CEL_KEL=273.16;
        printf("Fahrenheit = %.2f\n",fah);
        printf("Celsius = %.2f\n",fah*FAH_CEL_1+FAH_CEL_2);
        printf("Kelvin = %.2f\n",fah*FAH_CEL_1+FAH_CEL_2+CEL_KEL);
}

Please input an fahrenheit temperature
:123.3
Fahrenheit = 123.30
Celsius = 253.94
Kelvin = 527.10
Please input an fahrenheit temperature
:123.2
Fahrenheit = 123.20
Celsius = 253.76
Kelvin = 526.92

欢迎指正

#include

void temperatures(const double n);
int main()
{
double i;
printf("please shu ru temperatures:");
scanf("%lf",&i);
while( 1)
{
temperatures(i);
printf("shu ru or q tuichu");
scanf("%lf",&i);
}
return 0;
}
void temperatures(const double n)
{
const double i = 1.8*n + 32.0;
const double j = n + 273.6;
printf("%.2lf\n %.2lf\n %.2lf\n",i,n,j);
}

#include

void temperatures(const double n);
int main()
{
double i;
printf("please shu ru temperatures:");
scanf("%lf",&i);
while( 1)
{
temperatures(i);
printf("shu ru or q tuichu");
scanf("%lf",&i);
}
return 0;
}
void temperatures(const double n)
{
const double i = 1.8*n + 32.0;
const double j = n + 273.6;
printf("%.2lf\n %.2lf\n %.2lf\n",i,n,j);
}