功能检查有什么不对 [英] what the wrong in function check
本文介绍了功能检查有什么不对的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
int main()
case 4 :
{
bool c = a.check();
if (c == true )
{cout<< < span class =code-string> 数字是偶数<< endl;}
else
{cout<< 数字为奇数<< endl;}
break ;
}
函数,我称之为:
bool check()
{
cout<< 输入大整数:;
string s;
getline(cin,s);
string :: const_reverse_iterator s1 = s.rbegin();
if (* s1%2 == 0 )
{返回 true ;}
else
{返回 false ;}
}
解决方案
代码实际上是正确的,但仅限于行为良好的输入数据。
如果用户输入'aaaaaaaaaaaaaaaaaaaabbbbbbbbbb'
那么程序会将其识别为'even'
int main ()
case 4:
{
bool c=a.check();
if (c==true)
{cout <<"the number is even "<<endl;}
else
{cout <<"the number is odd "<<endl;}
break;
}
function which I call it :
bool check ( )
{
cout << "Enter big integer number :";
string s;
getline(cin,s);
string::const_reverse_iterator s1 = s.rbegin();
if (*s1 %2==0)
{return true;}
else
{return false;}
}
解决方案
The code is actually right, but only on well-behaved input data.
If the user, for instance inputs'aaaaaaaaaaaaaaaaaaaaabbbbbbbbbb'
then the programs recognizes it as'even'
.
这篇关于功能检查有什么不对的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文