+ 3

Palindrome numbers

I'm making a code that checks whether the number is a palindrome or not. Here is my code: #include <iostream> using namespace std; bool isPalindrome(int x) { //complete the function int n; int num; int digit; int rev; n = num; do { digit = num % 10; rev = (rev * 10) + digit; num = num / 10; } while (num != 0 ); return 0; } int main() { int n; cin >>n; if(isPalindrome(n)) { cout <<n<<" is a palindrome"; } else { cout << n<<" is NOT a palindrome"; } return 0; } I'm so close. The only issue is that it only corrects the numbers that are not palindrome, and not the ones that are palindromes. Can someone explain to me why this is happening? Thank you!

31st Dec 2022, 3:15 AM
Gradi Maxime Kasita Mbatika
4 Antworten
31st Dec 2022, 3:51 AM
Suparna Das
Suparna Das - avatar
+ 10
The bool function is used for return either true = 1 or false = 0 So that's why instead of calculating the reverse of number inside the bool function I have taken another int return type function named -> calculate In calculate function I have reversed the digit And called the reversed value in the bool function to evaluate the expression true or false with the original value I have checked ✔ ✅ it passes all the test conditions Hope it helps !
31st Dec 2022, 3:55 AM
Suparna Das
Suparna Das - avatar
+ 2
I do the change you can look at it https://code.sololearn.com/cQe3LKpROK7P/?ref=app
31st Dec 2022, 3:59 AM
Ab SH
+ 1
Thank you Suparna Das and Ab SH. My code now works! 👍
2nd Jan 2023, 8:55 PM
Gradi Maxime Kasita Mbatika