关于switch语句
#include "iostream.h"#include "math.h"
#include "stdio.h"
zz(char *,int);
void main()
{
char str1[8],*p1,*p2,a1,a2,*p;
int i,j1=0,j2=0,k=0;
double b1,b2;
cin>>str1;
p=str1;
for(i=0;i<8;i++)
{
if(str1[i]=='+'||str1[i]=='-'||str1[i]=='*'||str1[i]=='/')
break;
j1++;
}
p1=new char[j1];
for(i=0;i<j1;i++)
{
p1[i]=str1[i];
}
a1=str1[i+1];
for(i=i+1;i<8;i++)
{
if(str1[i]=='=')
break;
j2++;
}
p2=new char[j2];
for(i=0;i<j2;i++)
{
p2[i]=str1[i+j1+1];
}
a2=str1[j1+j2+2];
b1=zz(p1,j1);
//cout<<b1;
b2=zz(p2,j2);
cout<<b2;
//cout<<j1<<endl;
//cout<<j2;
if(a2=='=')
{
switch(a1)
case '+':cout<<b1<<"+"<<b2<<b1+b2;break;
case '-':cout<<b1<<"-"<<b2<<b1-b2;break;
case '*':cout<<b1<<"*"<<b2<<b1*b2;break;
case '/':
if(b2==0)
{
cout<<"error!!"<<endl;
}
else
cout<<b1<<"/"<<b2<<b1/b2;break;
default:
cout<<"输入错误:";break;
}
}
zz(char *p,int n)
{
double a,sum=0.00;
int i=0;
while(i<n)
{
a=(*p-48)*pow(10,n-1);
sum=sum+a;
//cout<<a<<endl;
p++;
n--;
}
return sum;
}
计算器的输出,结果要是保留两位小数,但是我的程序switch语句好像有点问题,麻烦帮忙看一下