我必须用 C 创建一个程序,允许用户输入度数和数字。我现在正在学习 C,很难判断我是否做得对。我不知道为什么我会得到这些未知的类型名称。我想使用 switch 语句、while 循环和转换器函数。
/* Fahrenheit/Celsius Converter */
#include <stdio.h> /* definitions of printf, scanf */
#include <math.h> /* definitions of sqrt, pow */
#define FCR 0.556 /* defines the value for FCR */
#define CFR 1.8 /* defines the value for CFR */
double fc_converter(double);
double cf_converter(double);
int
main(void)
{
double fahrenheit;
double celsius;
char degrees;
printf("Hello > Fahrenheit/Celsius Converter. Please enter F or C:");
scanf("%c", °rees);
while (degrees == 'F' || 'f' || 'c' || 'C' )
{
switch(degrees){
case 'F':
case 'f':
printf("Hello > Please enter a Fahrenheit degree number:");
scanf("%lf", &fahrenheit);
return(fc_converter(fahrenheit));
break;
case 'C':
case 'c':
printf("Hello > Please enter a Celsius degree number:");
scanf("%lf", &celsius);
return(cf_converter(celsius));
break;
default:
printf("The input is unknown!");
break;
}
break;
}
}
double fc_converter(double, fahrenheit)
{
if (fahrenheit >= -200) && (fahrenheit <= 200)
{
celsius = FCR * (fahrenheit - 32.00);
printf("The calculated value from the converter function is:%.2f", fahrenheit);
return celsius;
}
else
{
printf("Invalid Celsius temperature.");
return (celsius = sqrt(fahrenheit));
}
}
double cf_converter(double, celsius)
{
if(celsius >= - 200) && (celsius <= 200)
{
fahrenheit = CFR * celsius + 32.00;
printf("The calculated value from the converter function is:%.2f", celsius);
return fahrenheit;
}
else
{
printf("Invalid Fahrenheit temperature.");
return(fahrenheit = pow(celsius, 3));
}
}
错误:
HW3.c:44:22: error: unknown type name ‘fahrenheit’
HW3.c:61:22: error: unknown type name ‘celsius’
最佳答案
仅解决语法错误:
double fc_converter(double, fahrenheit)
应该是:
double fc_converter(double fahrenheit)
另一个错误非常相似。
关于c - C 中的未知类型错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42406124/