0
How can I use a function in a condition and check whether it's true or not?
4 odpowiedzi
+ 4
Xx Yyy
Your function should return a value then you can use that function in a condition.
Like:
bool isPalindrome() {
return true;
}
Now use in condition like:
if (isPalindrome ()) {
cout << "Palindrome";
}
+ 1
And if it wasn't a palindrome I will use else?
+ 1
Xx Yyy
There might be 2 situation one is yes and one is no so if condition is true then if block will execute otherwise else block.
0
if (function()) {...}
Note that function must return a Boolean or something that can be understood as a Boolean (e.g. an int)