Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/62.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 错误:在‘之前应为表达式;无效’;_C_Compiler Errors - Fatal编程技术网

C 错误:在‘之前应为表达式;无效’;

C 错误:在‘之前应为表达式;无效’;,c,compiler-errors,C,Compiler Errors,我使用的是Cloud 9环境,这段代码让我很头疼,我们把它分配给了一个任务,它显示了以下编译错误,我被这些错误卡住了 lab.c:在函数“main”中:lab.c:14:12:错误:应为表达式 在“无效”之前 getType(void) ^lab.c:14:12:错误:函数“getType”的参数太多 lab.c:4:7:注意:此处声明float getType(void) ^lab.c:在函数“getType”中:lab.c:20:5:警告:格式“%f” 应为“double”类型的参数,但参数

我使用的是Cloud 9环境,这段代码让我很头疼,我们把它分配给了一个任务,它显示了以下编译错误,我被这些错误卡住了

lab.c:在函数“main”中:lab.c:14:12:错误:应为表达式 在“无效”之前 getType(void)

^lab.c:14:12:错误:函数“getType”的参数太多 lab.c:4:7:注意:此处声明float getType(void)

^lab.c:在函数“getType”中:lab.c:20:5:警告:格式“%f” 应为“double”类型的参数,但参数2的类型为“float” (*)(int,int)“[-Wformat=] printf(“总机票价格:%.2f”,票券价格)

//按给定类型计算成本aircost
#包括
float-getType(void);
浮动票券价格(int类型,int noofseat);
内部主(空)
{
int型,noofseat;
printf(“输入类型(1或2):”;
scanf(“%d”,类型(&T);
printf(“输入座位数:”);
scanf(“%d”、&noofseat);
getType(void);
票务价格(类型、无票务);
返回0;
}
浮点getType(void)
{
printf(“总机票价格:%.2f”,票券价格);
}
浮动票券价格(int类型,int noofseat)
{
浮动价格;
如果(类型=1){
printf(“经济舱”);
类型=90000;
printf(“90000\n”);
Tprice=90000*noofseat;
printf(“总机票价格:%.2f”,Tprice);
返回0;
}
否则如果(类型=2){
printf(“商务类”\n);
类型=120000;
printf(“120000\n”);
Tprice=120000*noofseat;
printf(“总机票价格:%.2f”,Tprice);
}
else if(类型!=1 | | 2){
printf(“无效类型”);
返回1;
}
}

当您定义一个在C语言中不带参数的函数时,参数应显式为
void
。你做到了。调用函数时出错:

getType(void);
在这里,您必须省略
无效项

getType();
但是您的函数返回一个
浮点值
,您可能需要存储结果。你的函数实际上应该重新生成一个浮点数。目前,它没有返回任何内容,这导致了未定义的行为


再次编译代码并打开警告。代码中还有许多其他错误。例如,
if(type=1)
type
设置为1,然后输入代码块。您要检查该值,您应该使用
=

来检查该值。您不能将
void
作为参数传递。就让它空白吧。所以它将是
getType()这里不是您的问题,但是
ticketPrice
是一个函数,不是一个可用值。我希望运行
getType
会失败或打印奇怪的结果。您需要调用函数。
getType(void)==>
somevar=getType()但函数不返回值。请启用编译器警告。删除
float-getType(void){printf(“总机票价格:%.2f”,ticketPrice);}
float-getType(void)
getType(void)
type=1
-->
type==1
类型=1 | | 2
-->
键入=1&类型=2
噢,我明白了,我把if(type=1)改为(type==1),现在它已经编译好了,可以工作了,谢谢你解释:D
getType();