下面是一个计算器的程序 有一个错误 谁帮我看下 谢谢
#include<iostream.h> #include<math.h> #include<stdlib.h> typedef struct { float shu[10]; int top; }s_shu; s_shu shu; s_shu *shu_s=&shu;
typedef struct { char fu[10]; int top; }s_fu; s_fu fu; s_fu *fu_s=&fu;
int push_s(s_shu *s,float x) { if(s->top>=10) return 0; else { s->shu[++s->top]=x; return 1; } }
int push_f(s_fu *s,char x) { if(s->top>=10) return 0; else { s->fu[++s->top]=x; return 1; } }
char pop_f(s_fu *s) { if (s->top<0) return 0; else { s->top--; return(s->fu[s->top+1]); } }
float pop_s(s_shu *s) { if (s->top<0) return 0; else { s->top--; return(s->shu[s->top+1]); } } char gettop(s_fu *s) { if(s->top<0) return 0; else return(s->fu[s->top]); } class Tpoppy { public: Cpoppy(char a[20],int n); float Calculate(); private: int Fuhao(char fu1); float Jisuan(float a,int c,float b); }; Tpoppy::Cpoppy(char a[20],int n) { int i; float temp1,temp2=0; for(i=n;i>=0;i--) { if(a[i]>='\060') { { if (a[i]<'\060') break; else temp1=float(atoi(&a[i])); } } if(a[i]<'\060') { push_f(fu_s,a[i]);push_s(shu_s,temp1); } } } int Tpoppy::Fuhao(char fu1) { switch(fu1) { case '\057':return 4; case '\052':return 3; case '\055':return 2; case '\053':return 1; default:return 0; } } float Tpoppy::Jisuan(float a,int c,float b) { switch(c) { case 4:a=b/a;break; case 3:a=b*a;break; case 2:a=b-a;break; case 1:a=b+a;break; default:break; } return a; } float Tpoppy::Calculate() { float temp1,temp2; char temp3; temp1=pop_s(shu_s); do { temp2=pop_s(shu_s); temp3=pop_f(fu_s);
if(Fuhao(temp3)>=Fuhao(gettop(fu_s))) { temp1=Jisuan(temp1,Fuhao(temp3),temp2); } if(Fuhao(temp3)<Fuhao(gettop(fu_s))) { push_s(shu_s,Jisuan(pop_s(shu_s),Fuhao(pop_f(fu_s)),temp2)); goto loop; } } } //说错误出在这个地方 但我找不出原因
void main() { char a[20]; int i,n; float t; fu_s->top=0; shu_s->top=0; Tpoppy Apoppy; a[0]='+'; for(i=1;i<20;i++) { cin>>a[i]; if (a[i]==61) break; n=i; } Apoppy.Cpoppy(a,n); t=Apoppy.Calculate();
cout<<endl; for(i=1;i<=n+1;i++) { cout<<pop_f(fu_s)<<pop_s(shu_s); } cout<<endl<<t<<endl; }
E:\c\text\jisqi.cpp(142) : error C2059: syntax error : '}' 执行 cl.exe 时出错.
jisqi.exe - 1 error(s), 0 warning(s)
[此贴子已经被作者于2004-12-20 10:23:45编辑过]