编写c语言时候老提示错误error C2143: syntax error : missing ✀;✀ before ✀type✀ ,求高手帮忙指出

2025-03-06 11:24:35
推荐回答(4个)
回答1:

楼主程序没问题,只是多了个重复定义和输入格式中少了取地址运符。。。
这些问题只要认真点就能找到的,呵呵。。
以下是我的修正加注释,楼主说的那个问题似乎没有,如果老是出现你说这个情况可能是你输入法没切换到“键盘”的状态。。
#include
#include
#include
void main()
{
int i,x,y,n,result,r,count; //此处我将定义的m删了。。。。。。。。。。。
char op,flag;
srand(100);
//要求用户必须输入正确的运算符才可以.
printf("欢迎使用四则运算测试器(每次10道题).\n");
do{
printf("你想做哪一种运算(+,-,*,/)?");
scanf("%c",&op); //缺了取地址运算符。。。。。。。。。。。。。。。。
}
while(!(op=='+'||op=='-'||op=='*'||op=='/'));
printf("您想做几位数的四则运算?(1或2)");
scanf("%d",&n); //此处也是缺了取地址运算符。。。。。。。。。。。。
int m=1;
for(i=1;i<=n;i++);m=m*10;
do{
count=0;
for(i=0;i<10;i++){//要求用户每次必须做够10道题才可以,每题10分.

printf("\n");
x=rand()%m;
y=rand()%m;
switch(op){
case '+':r=x+y;break;
case '-':r=x-y;break;
case '*':r=x*y;break;
case '/':if(y==0) r=x/y; else r=0;
}
printf("%d,%c,%d",x,op,y,"=?");//cout<scanf("%d",&result); //此处也是缺了取地址运算符。。。。。。。。。。
if(r==result) {count+=10;printf("√\n");}else printf("×\n");
}//for
printf("你的最后得分是");printf("%d",count);printf("分\n");
printf("继续吗(y或n)?");
scanf("%c",&flag); //此处也是缺了取地址运算符。。。。。。。。。。。
}while(flag=='y'||flag=='Y');

printf("恭喜你,欢迎再次光临!\n");
}

回答2:

没有什么大错误,是error C2086: 'm' : redefinition。意思是变量重定义在前面已经定义过了。

回答3:

第二行:
#include //此处错误了,应该写为iomanip,而不能写为iomanip.h
第十八行:
//int m=1;//此处错误了,重复定义了m

回答4:

scanf("%c",op);改成scanf("%c",&op);

scanf("%d",n); 改成scanf("%d",&n);

scanf("%d",result); 改成scanf("%d",&result);

scanf("%c",flag); 改成scanf("%c",flag);