为什么输入正确符号后会显示“输入有误”
#include<iostream>#include<stdio.h>
#include<stdlib.h>
using namespace std;
float add(float a, float b)
{
return(a+b);
}
float minus(float a, float b)
{
return(a-b);
}
float multi(float a, float b)
{
return(a*b);
}
float div(float a, float b)
{
return(a/b);
}
float calculate(float a, float b, char k)
{
float s;
switch(k)
{
case '+':
s=add(a,b);
break;
case'-':
s=minus(a,b);
break;
case '*':
s=multi(a,b);
break;
case '/':
s=div(a,b);
break;
}
return(s);
}
int main()
{
float a,b;
char k;
cout<<" 简易计算器"<<endl;
cout<<"请输入运算符"<<endl;
cin>>k;
if(k!='*'||'-'||'+'||'/')
{
cout<<"输入有误"<<endl;
if(k=='#')
{
//cout<<"计算结束"<<endl;
}
}
cout<<"请输入运算数值"<<endl;
cin>>a>>b;
//cin.ignore (numeric_limits<std::streamsize >::max());
//cin.ignore (numeric_limits<std::streamsize>::max());
cout<<"结果为"<<calculate(a,b,k)<<endl;
system("pause");
return 0 ;
}