#include<iostream>
#include<iomanip>
using namespace std;
void main()
{
double leftoperand,rightoperand,result;
char operate;
cout<<"please input leftoperand operate rightoperand:"<<endl;
cin>>leftoperand>>operate>>rightoperand;
switch(operate)
{
case '+':
result=leftoperand+rightoperand;
break;
case '-':
result=leftoperand-rightoperand;
break;
case '*':
result=leftoperand*rightoperand;
break;
case '/':
if(rightoperand)
{result=leftoperand/rightoperand;
break;
}
else
{ cout<<"illegal operate input:"<<endl;
break;
}
}
cout<<leftoperand<<operate<<rightoperand<<"equals"<<result<<endl;
程序是正确的....只是我还有些疑问
如果我输入5+6回车 结果是:5+6equals11
可是如果我输入5空格+空格6回车 这样结果还是:5+6equals11
照理上面定义了operate是字符变量...应该把空格辅值给operate的啊!!!
求教!
}