【发布时间】:2015-10-07 20:55:26
【问题描述】:
我的布尔函数有问题。当我编译程序时,一切运行良好,但当我输入“否”时,它仍然说“我能帮你什么?”。
#include <iostream>
#include <string> //size()
#include <cctype> //isdigit()
using namespace std; //(xxx)xxx-xxxx
bool verification(string yesOrno)
{
if(yesOrno == "yes")return(true);
else return(false);
}
int main()
{
string yesOrno;
cout <<"Do you need more help\n";
cin >> yesOrno;
if(!verification(yesOrno))cout <<"What can I help you with?\n";
return(0);
}
【问题讨论】:
-
你能告诉我们
!false是什么吗? -
附带说明,您可以通过使用
return (yesOrno == "yes");来简化验证评估,而不是添加额外的步骤并使事情变得不必要。 -
@DrewDormann 答案是……
true -
第 2 行和第 4 行的 cmets 很神秘
-
@MattMcNabb 我读到这意味着 “评论 2 和 4(对这个问题)是神秘的”,并且......花了很多时间来欣赏这样的元观察。
标签: c++ function if-statement boolean