Reputation: 21
I have a class EverTrueHelper.cpp.
bool EverTrueHelper::getAndReturnUserEntry(string userEntry)
{
if (userEntry == "Q" || userEntry == "q")
{
return true;
}
else
{
return false;
}
return 0;
}
and I have these lines of code in my main function
cout << "Do you want to quit? Type 'Q' or 'q' else hit Enter" << endl;
cin >> userEntry;
if (getAndReturnUserEntry = true)
{
break;
}
else
{
continue;
}
I have an error on the "getAndReturnUserEntry" in my if
statement. I can't quite figure out how to get around it.
Upvotes: 1
Views: 90
Reputation: 193
You have two problem with your main
function's if
statement:
=
, which means assignment, which is invalid in that case.getAndReturnUserEntry
, add ()
at the end to actually invoke the function. After that, a test for == true
is not necessary either since it will work anyway.cout << "Do you want to quit? Type 'Q' or 'q' else hit Enter" << endl;
cin >> userEntry;
if (getAndReturnUserEntry())
{
break;
}
// continue program...
Further more, I think a better quit checking function will be:
bool EverTrueHelper::getAndReturnUserEntry(string userEntry)
{
return (userEntry == "Q" || userEntry == "q");
}
Upvotes: 1
Reputation: 151
You can try like follow:
cin >> userEntry;
EverTrueHelper my_helper;
if (my_helper.getAndReturnUserEntry(userEntry)) {
break;
}else{
continue;
}
Upvotes: 1
Reputation: 349
bool EverTrueHelper::getAndReturnUserEntry(string userEntry) {
return ((userEntry == "Q" || userEntry == "q") ? true : false);
}
cout << "Do you want to quit? Type 'Q' or 'q' else hit Enter" << endl;
cin >> userEntry;
if (getAndReturnUserEntry(userEntry) == true)
; // break; doesn't make sense here
else
; // continue; doesn't make sense here
Upvotes: 0
Reputation: 311508
You can call a method by using parentheses (()
) and passing the argument(s) in them:
cin >> userEntry;
if (getAndReturnUserEntry(userEntry))
{
break;
}
else
{
continue;
}
Upvotes: 2