第六行如果用doublede的话,就会出现垃圾数据,输入的数据无法传递到自定义函数中,用float就可以
double的范围不是更大吗,到底哪里出问题了?
各位大lao求解
这是一个输入华氏温度,输出华氏温度,摄氏温度,开氏温度的程序
#include<stdio.h>
void temperatures (double n);
int main(void)
{
float hua; //第六行,为什么能用float,double却不可以
int a;
printf("Enter the temperatures(华氏):");
a = scanf("%f", &hua);
while(a == 1)
{
temperatures(hua);
printf("Enter the temperatures(华氏) (not number exit):");
a = scanf("%f", &hua);
}
printf("bye!\n");
return 0;
}
void temperatures(double n)
{
const double SHESHI_1 = 5.0 / 9.0; //摄氏温度 = 5.0 / 9.0(华氏温度 - 32.0)
const double SHESHI_2 = 32.0;
const double KAISHI_1 = 273.16; //开氏温度 = 摄氏温度 + 273.16
double sheshi;
double huashi;
double kaishi;
huashi = n;
sheshi = SHESHI_1 * (huashi - SHESHI_2);
kaishi = sheshi + KAISHI_1;
printf("\n%.2f \n%.2f \n%.2f \n", huashi, sheshi, kaishi);
}
结果