#include
#include
void Temperatures(double n);
int main(void)
{
double Fahrenheit;
printf("输入华氏温度:\n");
scanf("%lf", &Fahrenheit);
while (Fahrenheit)
{
Temperatures(Fahrenheit);
printf("再次输入华氏温度:\n若要推出程序请输入非数字值\n");
scanf("%lf", &Fahrenheit);
}
system("pause");
return 0;
}
void Temperatures(double n)
{
const double 华氏转摄氏1 = 1.8;
const double 华氏转摄氏2 =32.0;
const double 摄氏转绝对 = 273.16;
double Celsius,Kelvin;
Celsius = n * 华氏转摄氏1+ 华氏转摄氏2;
Kelvin = Celsius + 摄氏转绝对;
printf("%.2f\n%.2f\n%.2f\n", n, Celsius, Kelvin);
}
就靠while()真的能做到“当用户输入q或其他非数字值时,循环结束”吗?因为学到第五章也就教了while()一种循环。能出这种题目应该时能做到的吧
#include
#include
void Temperatures(double n);
int main(void)
{
double Fahrenheit;
printf("输入华氏温度:\n");
while (scanf("%lf", &Fahrenheit))
{
Temperatures(Fahrenheit);
printf("再次输入华氏温度:\n若要推出程序请输入非数字值\n");
scanf("%lf", &Fahrenheit);
}
system("pause");
return 0;
}
void Temperatures(double n)
{
const double 华氏转摄氏1 = 1.8;
const double 华氏转摄氏2 =32.0;
const double 摄氏转绝对 = 273.16;
double Celsius,Kelvin;
Celsius = n * 华氏转摄氏1+ 华氏转摄氏2;
Kelvin = Celsius + 摄氏转绝对;
printf("%.2f\n%.2f\n%.2f\n", n, Celsius, Kelvin);
}
最后写成了这样