以下为书上代码:
#include<stdio.h>
int Temperatures(double hswd );
int main(int argc,char*argv[]){
double input;
printf("enter the temperatures:");
while(scanf("%lf",&input)==1){
Temperatures(input);
printf("vdxjsahbcj");
}
printf("this is the problem withe the number you entered! ");
return 0;
}
int Temperatures(double hswd ){
const double f_to_c=32.0;
const double c_to_k=273.16;
double sswd,kswd;
sswd=5.0/9.0*(hswd-f_to_c);
kswd=sswd+c_to_k;
printf("%.2f华氏温度计,%.2f摄氏温的,%.2f开氏温度\n",hswd,sswd,kswd);
return 0;
}
错误:
以下为在论坛找的代码:
#include<stdio.h>
void Temperatures(const double temperature)
{
const double Fahrenheit_val = 32.0;
const double Kelvin_val = 273.16;
const double Fahrenheit_temp = 5.0 / 9.0 * (temperature - Fahrenheit_val);
const double Kelvin_temp = temperature + Kelvin_val;
printf("Celsius: %.2lf Fahrenheit:%.2lf Kelvin:%.2lf\n", temperature, Fahrenheit_temp, Kelvin_temp);
return;
}
void p5_9(void)
{
double temperature = 0.0;
printf("please enter the temperature (q to quit):");
while (scanf_s("%lf", &temperature) == 1)
{
getchar();
Temperatures(temperature);
printf("please enter the temperature (q to quit):");
}
return;
}
int main(int argc, char **argv)
{
p5_9();
getchar();
return 1;
}
我以为是我软件的问题,因为它也点不开调试,用了mooc的在线语言开发环境: