C++ 定义double变量由用户输入 如何判断输入是否合法并作出不同反应?(今天讲了选择语句

{
double a=0,b=0,c=0; //定义并初始化方程参数
cout<<"Please input three reasonable numbers for the equaltion ax2+bx+c=0:"<<endl; //提示用户
cin>>a>>b>>c;
如何判断abc是否为合法输入?

double a=0,b=0,c=0,k; //定义并初始化方程参数
cout<<"Please input three reasonable numbers for the equaltion ax2+bx+c=0:"<<endl; //提示用户
cin>>a>>b>>c;
k=b*b-4*a*c;
if(k<0 || a==0)
cout<<"abc不是合法输入"<<endl;
温馨提示:答案为网友推荐,仅供参考
第1个回答  2011-10-18
不合法,首先,定义a,b,c时无需赋值。
相似回答