C++ Palindrome: I don't find a working code for the palindrome test. Please help :)
So I am stuck at the palindrome code of the C++ learning path. I tried many ways to find a working code but failed. Do you have any idea of how I should change this code to make it work? I just started to learn programming yesterday so there might be some serious and obvious mistakes in the code :) #include <iostream> using namespace std; bool isPalindrome(int x) { int i = x; int counter = 0; //finding out number of digits in x do { i = i%10; counter++; } while(i!=0); int array1[counter]; int array2[counter]; //filling array1 with digits of x for(int r=1; r<=counter; r++) { array1[counter-r] = x%10; x=x-array1[counter-r]; } //filling array2 with digits of x for(int r=0; r<counter; r++) { array2 [r] = x%10; x=x-array2[r]; } int k=0; //counting times of array1[r]=array2[r] for(int r = 0; r<counter; counter--,r++) { if(array1[r]==array2[r]) { k+=1; } } //comparing counter(number of digits of n) and k(how many times array1=array2) //if counter = k => n is a palindrome => function isPalindrome=true if(k==counter) { return 1; } else { 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; }