What am I missing here...? Answered! Thank you everyone. You are incredibly fast in answering my questions!! | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

What am I missing here...? Answered! Thank you everyone. You are incredibly fast in answering my questions!!

Hey guys. TRYING TO CREATE A BOOL FUNCTION HERE BUT SOMEWHERE THERE IS A MISTAKE... CANNOT FIGURE IT OUT. WHO CAN GIVE ME A HINT PLEASE? https://code.sololearn.com/c8Wc2aM7fKcJ/?ref=app

16th Dec 2020, 12:00 PM
The_Fox
The_Fox - avatar
3 Answers
+ 6
1) You are not returning anything if you *if* statement at like 12 is false. Possible Fix: add a simple "return false" there 2) you are messing up your original number *x* during reversing it which will always fail the condition (x == reversenumber) Possible Fix: do the operations on a duplicate instead Here is how your program will look after applying all the fixes 👇 https://code.sololearn.com/cmxyn2sexKeU/?ref=app
16th Dec 2020, 12:12 PM
Arsenic
Arsenic - avatar
+ 2
Thank you. Yes, I also tried your version of the duplicate before... :)
16th Dec 2020, 12:14 PM
The_Fox
The_Fox - avatar
+ 1
#include <iostream> using namespace std; bool isPalindrome(int n) { int x = n; int reversedNumber = 0, remainder; while(x != 0) { remainder = x%10; reversedNumber = reversedNumber*10 + remainder; x /= 10; } return n == reversedNumber; //check if inputted number = reversedNumber } int main() { int n = 111; if(isPalindrome(n)) { cout <<n<<" is a palindrome"; } else { cout << n<<" is NOT a palindrome"; } return 0; }
16th Dec 2020, 12:12 PM
Flash