主题:哪拉大侠帮我看看这段代码是错在哪的
#define max 80
#include<stdio.h>
#include"1.h"
#include<math.h>
main()
{int i=0,j=0,bi,b1,B=0;
double n,m1,m2,m=0;
char k[max],ch='\0',x;
shuju a;
yunsuanfu b;
chushihua1(&a);
chushihua2(&b);
charu2(&b,'\0');
jiemian();
gets(k);
while(k[i]!='\0')
{if(k[j]=='s'&&k[j+2]=='n')
{j=j+3;i=j;B=1;}
else if(k[j]=='c'&&k[j+2]=='s')
{j=j+3;i=j;B=2;}
else if(k[j]=='t'&&k[j+2]=='n')
{j=j+3;i=j;B=3;}
else if(k[j]=='l'&&k[j+2]=='g')
{j=j+3;i=j;B=4;}
else if(k[j]=='l'&&k[j+1]=='n')
{j=j+2;i=j;B=5;}
while(k[j]=='.'||(k[j]>='0'&&k[j]<='9'))j++;
n=zhuanhuan(i,j,k);
switch(B)
{
case 1: n=sin(n);break;
case 2: n=cos(n);break;
case 3: n=tan(n);break;
case 4: n=log10(n);break;
case 5: n=log(n);
}
charu1(&a,n);
b1=0;
while(b1==0)
{bi=op(ch,k[j]);
if(bi==0)jieshu();
while(bi==1)
{m=f1(&a,&b);
chuzhuan2(&b,&ch);
bi=op(ch,k[j]);
charu2(&b,ch);
}
if(bi==-1)
{do{f2(j,&b,k);j++;}
while(k[j]=='(');
j--;
}
else if(bi==2)
{
if(ch=='(')
{if(k[j]==')')j++;
chuzhuan2(&b,&ch);
chuzhuan2(&b,&ch);
charu2(&b,ch);
continue;
}
else chuzhuan1(&a,&m);
}
b1=1;
}
if(k[j]=='\0')break;
else{ch=k[j];j++;}
i=j;B=0;
}
printf("\t\t\t");
textcolor(30);
cprintf("The answer is %f",m);
printf("\n");
jieshu();
}
[size=4]七处错误:[/size]
[img]http://b39.photo.store.qq.com/http_imgload.cgi?/rurl4_b=bd6c90a0ba13248b9f664fd32cea12903ca7fbfd29328feebd8614e3c3d880f45b2bec1a61d0598ca23a27b992eb94f183e5f40ab66a103ca41619882c61dfddf7f1e754fd225333664f265afdfdb91e1840989d&a=42&b=39[/img]
-------------------------------------------------------------------------------
上面是主程序,下面 是“1.h”里面的代码:
#define max1 40
#define max2 40
#define NULL 0
typedef struct
{double A[max1];
int top1;
}shuju;
typedef struct
{char B[max2];
int top2;
}yunsuanfu;
void chushihua1(shuju *p)
{p->top1=0;}
void chushihua2(yunsuanfu *p)
{p->top2=0;}
int charu1(shuju *p,double x)
{if(p->top1>=(max1-1))
{printf("you are wrong1\n");
return 0;
}
else {p->A[p->top1]=x;
p->top1++;
return 1;
}
}
int charu2(yunsuanfu *p,char x)
{if(p->top2>=(max2-1))
{printf("you are wrong2\n");
return 0;
}
else {p->B[p->top2]=x;
p->top2++;
return 1;
}
}
int chuzhuan1(shuju *p,double *x)
{if(p->top1<0)
{printf("you are wrong11\n");
return 0;
}
else {p->top1--;
*x=p->A[p->top1];
return 1;
}
}
int chuzhuan2(yunsuanfu *p,char *x)
{if(p->top2<0)
{printf("you are wrong22\n");
return 0;
}
else {p->top2--;
*x=p->B[p->top2];
return 1;
}
}
int op(char f,char b)
{if((f=='('&&b==')')||(f=='\0'&&b=='\0'))return 2;
else if(((b=='*'||b=='/')&&(f=='+'||f=='-'))||(b=='('&&f!=')')||((f=='('||f=='\0')&&(b=='+'||b=='/'||b=='-'||b=='*')))
return -1;
else if((b=='\0'&&f!='(')||(b==')'&&f!='\0')||b==f||((f=='*'||f=='/'||f==')')&&(b=='+'||b=='/'||b=='-'||b=='*')))
return 1;
else{printf("\t\t\tyou are wrong\n");return 0;}
}
double zhuanhuan(int x,int y,char a[])
{int i,j=0,k;
double n=0;
for(i=x;i<y;i++)
{if(a[i]!='.')
n=n*10+a[i]-'0';
else j=i;
}
if(j==0)return n;
else{for(k=0;k<i-1-j;k++)
n=n/10;
return n;
}
}
double f1(shuju *a,yunsuanfu *b)
{double m,m1,m2;char x;
chuzhuan2(b,&x);
chuzhuan1(a,&m1);
chuzhuan1(a,&m2);
if(x=='*')m=m1*m2;
else if(x=='+')m=m1+m2;
else if(x=='-')m=m2-m1;
else if(x=='/')
if(m1==0)
{printf("\t\t\tyou are wrong\n");jieshu();}
else m=m2/m1;
charu1(a,m);
return m;
}
void f2(int j,yunsuanfu *b,char k[])
{charu2(b,k[j]);}
void jiemian()
{system("cls");
printf("\n");
printf("\t\t\t C O U N T E R\n");
textcolor(5);
cprintf("*******************************************************************************");
printf("\n\n");
printf("\t\t\tPlease input your exprssion\n");
printf("\t\t\t ");
}
jieshu()
{char c;
printf("Are you contiune?(y/n) ");
while(1)
{c=getch();printf("\n");
if(c=='y'||c=='Y')main();
else if(c=='n'||c=='N')
{system("cls");
printf("\n\n\t\t\t Thank you use the counter\n");
printf("\t\t\t");
getch();exit(0);
}
else{printf("\t\t\t");
cprintf("Please input y/n!");printf("\n");
printf("\t\t\t");
continue;
}
}
return NULL;
}
1.H一两处错误:
[img]http://b39.photo.store.qq.com/http_imgload.cgi?/rurl4_b=bd6c90a0ba13248b9f664fd32cea12909c876728d8b3bc7695019e8ac0cbe1b0154707f68629f3a94776811049bef4013721c763ef85d7e6de6d5c0d3e3bfb33ab9a0b3259f3a6843effbb7ff953bf12a7067962&a=38&b=39[/img]
#include<stdio.h>
#include"1.h"
#include<math.h>
main()
{int i=0,j=0,bi,b1,B=0;
double n,m1,m2,m=0;
char k[max],ch='\0',x;
shuju a;
yunsuanfu b;
chushihua1(&a);
chushihua2(&b);
charu2(&b,'\0');
jiemian();
gets(k);
while(k[i]!='\0')
{if(k[j]=='s'&&k[j+2]=='n')
{j=j+3;i=j;B=1;}
else if(k[j]=='c'&&k[j+2]=='s')
{j=j+3;i=j;B=2;}
else if(k[j]=='t'&&k[j+2]=='n')
{j=j+3;i=j;B=3;}
else if(k[j]=='l'&&k[j+2]=='g')
{j=j+3;i=j;B=4;}
else if(k[j]=='l'&&k[j+1]=='n')
{j=j+2;i=j;B=5;}
while(k[j]=='.'||(k[j]>='0'&&k[j]<='9'))j++;
n=zhuanhuan(i,j,k);
switch(B)
{
case 1: n=sin(n);break;
case 2: n=cos(n);break;
case 3: n=tan(n);break;
case 4: n=log10(n);break;
case 5: n=log(n);
}
charu1(&a,n);
b1=0;
while(b1==0)
{bi=op(ch,k[j]);
if(bi==0)jieshu();
while(bi==1)
{m=f1(&a,&b);
chuzhuan2(&b,&ch);
bi=op(ch,k[j]);
charu2(&b,ch);
}
if(bi==-1)
{do{f2(j,&b,k);j++;}
while(k[j]=='(');
j--;
}
else if(bi==2)
{
if(ch=='(')
{if(k[j]==')')j++;
chuzhuan2(&b,&ch);
chuzhuan2(&b,&ch);
charu2(&b,ch);
continue;
}
else chuzhuan1(&a,&m);
}
b1=1;
}
if(k[j]=='\0')break;
else{ch=k[j];j++;}
i=j;B=0;
}
printf("\t\t\t");
textcolor(30);
cprintf("The answer is %f",m);
printf("\n");
jieshu();
}
[size=4]七处错误:[/size]
[img]http://b39.photo.store.qq.com/http_imgload.cgi?/rurl4_b=bd6c90a0ba13248b9f664fd32cea12903ca7fbfd29328feebd8614e3c3d880f45b2bec1a61d0598ca23a27b992eb94f183e5f40ab66a103ca41619882c61dfddf7f1e754fd225333664f265afdfdb91e1840989d&a=42&b=39[/img]
-------------------------------------------------------------------------------
上面是主程序,下面 是“1.h”里面的代码:
#define max1 40
#define max2 40
#define NULL 0
typedef struct
{double A[max1];
int top1;
}shuju;
typedef struct
{char B[max2];
int top2;
}yunsuanfu;
void chushihua1(shuju *p)
{p->top1=0;}
void chushihua2(yunsuanfu *p)
{p->top2=0;}
int charu1(shuju *p,double x)
{if(p->top1>=(max1-1))
{printf("you are wrong1\n");
return 0;
}
else {p->A[p->top1]=x;
p->top1++;
return 1;
}
}
int charu2(yunsuanfu *p,char x)
{if(p->top2>=(max2-1))
{printf("you are wrong2\n");
return 0;
}
else {p->B[p->top2]=x;
p->top2++;
return 1;
}
}
int chuzhuan1(shuju *p,double *x)
{if(p->top1<0)
{printf("you are wrong11\n");
return 0;
}
else {p->top1--;
*x=p->A[p->top1];
return 1;
}
}
int chuzhuan2(yunsuanfu *p,char *x)
{if(p->top2<0)
{printf("you are wrong22\n");
return 0;
}
else {p->top2--;
*x=p->B[p->top2];
return 1;
}
}
int op(char f,char b)
{if((f=='('&&b==')')||(f=='\0'&&b=='\0'))return 2;
else if(((b=='*'||b=='/')&&(f=='+'||f=='-'))||(b=='('&&f!=')')||((f=='('||f=='\0')&&(b=='+'||b=='/'||b=='-'||b=='*')))
return -1;
else if((b=='\0'&&f!='(')||(b==')'&&f!='\0')||b==f||((f=='*'||f=='/'||f==')')&&(b=='+'||b=='/'||b=='-'||b=='*')))
return 1;
else{printf("\t\t\tyou are wrong\n");return 0;}
}
double zhuanhuan(int x,int y,char a[])
{int i,j=0,k;
double n=0;
for(i=x;i<y;i++)
{if(a[i]!='.')
n=n*10+a[i]-'0';
else j=i;
}
if(j==0)return n;
else{for(k=0;k<i-1-j;k++)
n=n/10;
return n;
}
}
double f1(shuju *a,yunsuanfu *b)
{double m,m1,m2;char x;
chuzhuan2(b,&x);
chuzhuan1(a,&m1);
chuzhuan1(a,&m2);
if(x=='*')m=m1*m2;
else if(x=='+')m=m1+m2;
else if(x=='-')m=m2-m1;
else if(x=='/')
if(m1==0)
{printf("\t\t\tyou are wrong\n");jieshu();}
else m=m2/m1;
charu1(a,m);
return m;
}
void f2(int j,yunsuanfu *b,char k[])
{charu2(b,k[j]);}
void jiemian()
{system("cls");
printf("\n");
printf("\t\t\t C O U N T E R\n");
textcolor(5);
cprintf("*******************************************************************************");
printf("\n\n");
printf("\t\t\tPlease input your exprssion\n");
printf("\t\t\t ");
}
jieshu()
{char c;
printf("Are you contiune?(y/n) ");
while(1)
{c=getch();printf("\n");
if(c=='y'||c=='Y')main();
else if(c=='n'||c=='N')
{system("cls");
printf("\n\n\t\t\t Thank you use the counter\n");
printf("\t\t\t");
getch();exit(0);
}
else{printf("\t\t\t");
cprintf("Please input y/n!");printf("\n");
printf("\t\t\t");
continue;
}
}
return NULL;
}
1.H一两处错误:
[img]http://b39.photo.store.qq.com/http_imgload.cgi?/rurl4_b=bd6c90a0ba13248b9f664fd32cea12909c876728d8b3bc7695019e8ac0cbe1b0154707f68629f3a94776811049bef4013721c763ef85d7e6de6d5c0d3e3bfb33ab9a0b3259f3a6843effbb7ff953bf12a7067962&a=38&b=39[/img]