First, you should not use global variables for num and pwr ; you must pass them as arguments to the functions:
bool isNumPalindrome(int num); ... num = askNumber(); isNumPalindrome(num);
Secondly, there is no need to compare a boolean with true (or false ); just use the boolean value.
It's hard to say exactly which syntax you are trying to use if in your example, but one thing you cannot do is the if statement in the expression. In C ++, there are expressions and statements. Expressions matter; There are no allegations.
// valid if (isNumPalindrome(num)) { std::cout << '"' << num << "\" is a palindrome." << std::endl; } else { std::cout << '"' << num << "\" is not a palindrome." << std::endl; } // invalid std::cout << '"' << num << (if (isNumPalindrome(num)) { "\" is a palindrome."; } else { "\" is not a palindrome."; }) << std::endl; // valid, but not recommended std::cout << '"' << num << "\" is " << (isNumPalindrome(num) ? "" : "not ") << "a palindrome." << std::endl;
For the ternary operator (? :), read " To ternary or not to triple? "
outis
source share