大家帮忙改一下错
/*-------------------------------------------------calculator
Author:Wrf
Date:mm//dd//yy
--------------------------------------------------*/
/*-----------PREPROCESING DIRECTIVES---------------*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
#include <malloc.h>
#include <math.h>
/*-----------------PROGRAM VARIABLES-----------------*/
#define STACK_INIT_SIZE 100
#define STACKINCREMENT 10
typedef struct {
float data; /*存放操作数或者计算结果*/
char ch; /*存放运算符*/
}SNode;
typedef struct {
SNode *base,*top;
int stacksize;
}Stack;
char c;
/*--------------------------------------------------------
MAINLINE CONTROL
---------------------------------------------------------*/
main()
{float iresult;
char ch;
L1:iresult=EvaluatExpression();
printf("\nThe iresult is:%d\n");
printf("Do you want to exit,please input y||n\n");
if(ch=='y'||ch=='Y')
return;
else
{ goto L1;}
return 0;
}
/*--------------------EvaluatExpression--------------------*/
EvaluatExpression()
{ Stack OPTR,OPND,S;
SNode e,a,b;
char c,x,theta;
InitStack( OPTR); Push(OPTR,'#');
InitStack( OPND); c=getchar();
while(c!='#'|| GetTop(OPTR)!='#')
{
if(!In(c)){Push((OPND),c);c=getchar();}
else
switch(Precede(GetTop(OPTR),c))
{case '<':
Push(OPTR,c);c=getchar();
break;
case '=':
Pop(OPTR,x);c=getchar();
break;
case '>':
Pop(OPTR,theta);
Pop(OPND,b);Pop(OPND,a);
Push(OPND,Operate(a,theta,b));
break;
}/*switch*/
}/*while*/
return GetTop(OPND);
}/*EvaluatExpression*/
/*--------------------InitStack--------------------------*/
int InitStack(Stack &S)
{
S.base=(SNode *)malloc(STACK_INIT_SIZE * sizeof(struct SNode));
if(S.base==NULL)
{
printf("动态分配内存失败!");
return -1;
}
S.top=S.base;
S.stacksize=STACK_INIT_SIZE;
return 0;
}/*InitStack*/
/*------------------------GetTop---------------------------*/
GetTop(Stack &S,SNode &e)
{
if(S.top==S.base)return -1;
e=*(S.top-1);
return 1;
}/*GetTop*/
/*-------------------------Push----------------------------*/
Push(Stack &S,SNode &e)
{
if(S.top-S.base>=S.stacksize)
{
S.base=(SNode *)realloc(S.base,
(S.stacksize+STACKINCREMENT *sizeof(struct SNode)));
if(!S.base)exit(OVERFLOW);
S.top=S.base+S.stacksize;
S.stacksize+=STACKINCREMENT ;
}
*S.top=e;
S.top++;
return 1;
}/*Push*/
/*---------------------------Pop----------------------------*/
Pop(Stack &S,SNode &e)
{
if(S.top==S.base)return -1;
e==*(--S.top);
return 1;
}/*Pop*/
/*---------------------------IN----------------------------*/
In(c)
{ if(c=='+'||c=='-'||c=='*'||c=='/'||c=='('||c==')'||c=='=')
return 0;
else
return 1;
}
/*-----------------------------Precede---------------------*/
char Precede(char s,char c)
{{
switch(s)
{
case '+':
case '-':
if(c=='+'||c=='-')
return '>';
else if(c=='*'||c=='/')
return '<';
else if(c=='(')
return '<';
else if(c==')')
return '>';
else if(c=='c'||c=='s'||c=='l'||c=='t'||c=='o'||c=='!')
return '<';
else
return '>';
case '*':
case '/':
if(c=='+'||c=='-')
return '>';
else if(c=='*'||c=='/')
return '>';
else if(c=='(')
return '<';
else if(c==')')
return '>';
else if(c=='c'||c=='s'||c=='l'||c=='t'||c=='o'||c=='!')
return '<';
else
return '>';
case '(':
if(c=='+'||c=='-')
return '<';
else if(c=='*'||c=='/')
return '<';
else if(c=='(')
return '<';
else if(c==')')
return '=';
else if(c=='c'||c=='s'||c=='l'||c=='t'||c=='o'||c=='!')
return '<';
else
return 'E';
case ')':
if(c=='+'||c=='-')
return '>';
else if(c=='*'||c=='/')
return '>';
else if(c=='(')
return 'E';
else if(c==')')
return '>';
else if(c=='c'||c=='s'||c=='l'||c=='t'||c=='o'||c=='!')
return '>';
else
return '>';
case '#':
if(c=='+'||c=='-')
return '<';
else if(c=='*'||c=='/')
return '<';
else if(c=='(')
return '<';
else if(c==')')
return 'E';
else if(c=='c'||c=='s'||c=='l'||c=='t'||c=='o'||c=='!')
return '<';
else
return '=';
default:
break;
}
return ;
}
/*------------------------- Operate--------------------------*/
float Operate(float x, char opr, float y)
{
float result;
switch (opr)
{
case '+':
result = x + y;
break;
case '-':
result = x - y;
break;
case '*':
result = x * y;
break;
case '/':
if (y == 0)
{
printf("Divided by zero!\n");
return 0;
}
else
{
result = x / y;
break;
}
default:
printf("Bad Input.\n");
return 0;
}
return result;
} }
程序还未写完