急救,求高手指点
#include"stdio.h"
#include"string.h"
int add(int x,int y) { return x+y;}
int sub(int x,int y) { return x-y;}
int mul(int x,int y) { return x*y;}
int div(int x,int y) { return x/y;}
int (*func[])(int x,int y)={add,sub,mul,div};
int num,curch;
char chtbl[]="+-*/()=";
char corch[]="+-*/()=0123456789";
int getach()
{
unsigned int i;
while (true)
{
curch=getchar();
if (curch=EOF) return -1;
for (i=0;corch[i]&&curch !=corch[i];i++);
if (i<strlen(corch)) break;
}
return curch;
}
int getid()
{
int i;
if (curch>='0'&&curch<='9')
{
for(num=0;curch>='0'&&curch<='9';getach())
num=num*10+curch-'0';//this is myself
return -1;
}
else
{
for(i=0;chtbl[i];i++)
if(chtbl[i]==curch) break;
if (i<=5) getach();
return i;
}
}
int cal()
{
int x1,x2,x3,op1,op2,i;
i=getid();
if(i=4)
x1=cal();
else
x1=num;
op1=getid();
if(op1>=5) return x1;
i=getid();
if(i=4)
x2=cal();
else
x2=num;
op2=getid();
while((op2>=0)&&(op2<6)) //this is myself
{
i=getid();
if(i=4)
x3=cal();
else
x3=num;
if((op1/2==0)&&(op2/2==1))
x2=func[op2](x2,x3);
else
{ x1=func[op1](x1,x2); //this is myself
x2=x3;
op2=op1; //this is myself
}
op2=getid();
}
op2=getid();
}
return func[op1](x1,x2); //..............这一行
}
void main()
{
int value;
printf ("Please input an expression:\n");
getach();
while(curch != '=')
{
value=cal();
printf("The result is :%d\n",value);
printf("Please input an expression:\n");
getach();
}
}
//this is my self 有错吗 这个都是我填空填上去的 想看下对不对 但是
1>acount.cpp
1>c:\users\asus\documents\visual studio 2008\projects\count\count\acount.cpp(75) : error C2059: 语法错误 : “return”
1>c:\users\asus\documents\visual studio 2008\projects\count\count\acount.cpp(76) : error C2059: 语法错误 : “}”
1>c:\users\asus\documents\visual studio 2008\projects\count\count\acount.cpp(76) : error C2143: 语法错误 : 缺少“;”(在“}”的前面)
1>c:\users\asus\documents\visual studio 2008\projects\count\count\acount.cpp(76) : error C2059: 语法错误 : “}”
1>c:\users\asus\documents\visual studio 2008\projects\count\count\acount.cpp(78) : error C2143: 语法错误 : 缺少“;”(在“{”的前面)
1>c:\users\asus\documents\visual studio 2008\projects\count\count\acount.cpp(78) : error C2447: “{”: 缺少函数标题(是否是老式的形式表?)
1>生成日志保存在“file://c:\Users\ASUS\Documents\Visual Studio 2008\Projects\count\count\Debug\BuildLog.htm”
1>count - 6 个错误,0 个警告
========== 生成: 成功 0 个,失败 1 个,最新 0 个,跳过 0 个 ==========
//..............这一行
有错吗 他还有其他的选择(*func[op1])(x1,x2) 哪个呢?
[解决办法]
提示很清楚了,一条一条修正吧
[解决办法]
仅供参考
#include <stdio.h>double A[300][100];double valuex[300];double valuey[300];int i;double fun00(double x,double y) {return x + y ;};double fun01(double x,double y) {return x*x+ 3*y ;};double fun02(double x,double y) {return x + 2*y*x;};//... fun03(double x,double y) {return ...+... ;};//...//... fun98(double x,double y) {return ...+... ;};double fun99(double x,double y) {return x/2+20*y ;};double (*funNN[100])(double,double)={ fun00, fun01, fun02,// fun03,// ...// fun98, fun99,};int main() { double x,y; int f,FN; for (i=0;i<300;i++) { valuex[i]=(double)i; valuey[i]=(double)i; } FN=3; for (i=0;i<300;i++) { x=valuex[i]; y=valuey[i]; for (f=0;f<FN;f++) A[i][f]=funNN[f](x,y); } for (i=0;i<3;i++) { for (f=0;f<FN;f++) printf("%lg ",A[i][f]); printf("\n"); } return 0;}//0 0 0//2 4 3//4 10 10
[解决办法]
偶遇到类似问题都是用
“每次用/*...*/注释掉不同部分再重新编译,直到定位到具体语法出错的位置。”
的方法解决的。
[解决办法]
排错的意识都没有,还写什么程序。
[解决办法]
1.return func[op1](x1,x2); //..............这一行全面的“}”去掉,你没发现括号的数量不对应吗?
2.定义的div函数好像有系统的冲突,改一下函数名字就可以了。