问一个C语言的问题
13行的while语句,我想用它来判断输入的是一个double型还是一个字符,以判断是否结束循环。可是不知道该怎么做。用scanf可以实现么?谢谢了!程序代码:
#include <stdio.h> /* 华氏温度转摄氏温度、开氏温度 */ double Temperature (double x); /* 转换并打印温度的函数 */ int main (void) { double fahrenheit; printf ("Please enter the tempreture in Fahrenheit (non-number to quit) :"); scanf ("%lf", &fahrenheit); while () { Temperature (fahrenheit); printf ("Please enter the tempreture in Fahrenheit (non-number to quit) :"); scanf ("%lf", &fahrenheit); } return 0; } /* 转换并打印温度的函数 */ double Temperature (double x) { const double FAHRENHEIT_TO_CELCIUS_BY = 1.8, double FAHRENHEIT_TO_CELCIUS_PLUS = 32.0, double CELCIOUS_TO_KELVIN = 273.16; double celcius, kelvin; celcius = FAHRENHEIT_TO_CELCIUS_BY * x + FAHRENHEIT_TO_CELCIUS_PLUS; kelvin = celcius + CELCIOUS_TO_KELVIN; printf ("%.2lf Fahrenhit = %.2lf Celcious = %.2lf Kelvin\n", x, celcius, kelvin); }
[ 本帖最后由 DarylL 于 2013-1-31 20:43 编辑 ]