逆波兰计算器老是实现不了
int main(){
char c;
char neb={0};
int i=0;
double n,a,b;
on();
printf("请按逆波兰表达式输入,数字间用空格隔开:\n");
while(c!='#')
{
c=getchar();
if(ynneb(c)||c=='.')
{
//提取
neb=c;
i++;
}
if(c=' ')
{
neb='\0';
n=atof(neb);
push(n);
i=0;
}
switch(c)
{
case '+':a=pop();b=pop();push(a+b); break;
case '-':a=pop();b=pop();push(a-b); break;
case '*':a=pop();b=pop();push(a*b); break;
case '/':
{
a=pop();b=pop();
if(a=0)
{
printf("\n错误,被除数为0\n");
}
else push(b/a);
};break;
}
}
a=pop();
printf("\n结果是:\n");
printf("%f\n",a);
}
页:
[1]