麻烦帮忙看下 谢谢~~~
大家好 我最近刚开始学 下面的程序是对三个数进行四则运算,可不知道哪里错了 希望各位大侠指教#include "iostream.h"
int main()
{
float a,b,c;
char oper1,oper2;
cout<<"请输入一个表达式(eg.1+2*3):"<<endl;
cin>>a>>oper1>>b>>oper2>>c;
switch(oper1)
{
case'+':
{
switch(oper2)
{
case'+':
{
cout<<a<<oper1<<b<<oper2<<c<<a+b+c<<endl;
break;
}
case'-':
{
cout<<a<<oper1<<b<<oper2<<c<<a+b-c<<endl;
break;
}
case'*':
{
cout<<a<<oper1<<b<<oper2<<c<<a+b*c<<endl;
break;
}
case'/':
{
if(c!=0)cout<<a<<oper1<<b<<oper2<<c<<a+b/c<<endl;
else cout<<"出错了!"<<endl;
break;
}
default:
cout<<"出错了!"<<endl;
}
}
////////////////////////
case'-':
{
switch(oper2)
{
case'+':
{
cout<<a<<oper1<<b<<oper2<<c<<a-b+c<<endl;
break;
}
case'-':
{
cout<<a<<oper1<<b<<oper2<<c<<a-b-c<<endl;
break;
}
case'*':
{
cout<<a<<oper1<<b<<oper2<<c<<a-b*c<<endl;
break;
}
case'/':
{
if(c!=0)cout<<a<<oper1<<b<<oper2<<c<<a-b/c<<endl;
else cout<<"出错了!"<<endl;
break;
}
default:
cout<<"出错了!"<<endl;
}
}
//////////////////
case'*':
{
switch(oper2)
{
case'+':
{
cout<<a<<oper1<<b<<oper2<<c<<a*b+c<<endl;
break;
}
case'-':
{
cout<<a<<oper1<<b<<oper2<<c<<a*b-c<<endl;
break;
}
case'*':
{
cout<<a<<oper1<<b<<oper2<<c<<a*b*c<<endl;
break;
}
case'/':
{
if(c!=0)cout<<a<<oper1<<b<<oper2<<c<<a*b/c<<endl;
else cout<<"出错了!"<<endl;
break;
}
default:
cout<<"出错了!"<<endl;
}
}
////////////////////////
case'/':
{
if(b!=0)
{
switch(oper2)
{
case'+':
{
cout<<a<<oper1<<b<<oper2<<c<<a/b+c<<endl;
break;
}
case'-':
{
cout<<a<<oper1<<b<<oper2<<c<<a/b-c<<endl;
break;
}
case'*':
{
cout<<a<<oper1<<b<<oper2<<c<<a/b*c<<endl;
break;
}
case'/':
{
if(c!=0)cout<<a<<oper1<<b<<oper2<<c<<a/b/c<<endl;
else cout<<"出错了!"<<endl;
break;
}
default:
cout<<"出错了!"<<endl;
}
}
else
cout<<"出错了!"<<endl;
}
}
return 0;
}