c++ - Boolean function problems -
having trouble boolean function. when compile program runs fine, yet when type in "no" still says "what can with?".
#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 need more help\n"; cin >> yesorno; if(!verification(yesorno))cout <<"what can with?\n"; return(0); }
your logic backwards - verification
returns false
isn't "yes"
. since "no"
isn't "yes"
, verification("no")
returns false
, , in main
function print out message if !verification("no")
, evaluates true
.
seems should drop !
operator if
statement.
Comments
Post a Comment