c语言 - 出现"expected expression before '=' token"错误



这是有问题的代码:

double cf_converter(double t){
//This function converts from celsius to farenheit
if (t <= 200 && t >= -200){
printf("0.00 C ==> 32.00 F");
return CFR*t+32.00;
}
else{
printf("Invalid Farenheit Temperaturen");
return pow(t,3);
}
}

上面的函数是编译器告诉我发生错误的地方。我查看了其他示例,但我无法确定为什么会出现错误。根据编译器的说法,错误显然发生在第一个返回语句中,其中读取 CFR*t+32.00。

void main(){
//Main Loop
char c;
double t, o, input;
printf("Please enter  F or C: ");
scanf("%c", &c);
switch(c){
case 'c':
case 'C':
printf("nPlease enter a celsius degree number: ");
scanf("%lf", t);
o = cf_converter(t);
break;
case 'f':
case 'F':
printf("nPlease enter a farenheit degree number: ");
scanf("%lf", t);
o = fc_converter(t);
break;
default:
printf("nThat input is unknown.");
break;
}
}

以上是我目前编写的主要功能。有一个 fc_converter(( 函数与 cf_converter 函数相同,只是返回语句略有不同。我正在使用stdio.h和math.h来实现某些函数(如pow(t,3((。

在回答问题时,CFR 看起来像这样:

#define CFR = 1.8

更改以下内容:

#define CFR = 1.8

对此:

#define CFR 1.8

因为等号在语法上不正确。

此外,更改此设置:

scanf("%lf", t);

对此:

scanf("%lf", &t);

由于f属于double型。它与char c;完全相同的理性,您已经正确传递了其 scanf 调用的地址。

PS:main(( 在 C 和 C++ 中应该返回什么?int,而不是void

最新更新