/* the thing is that i need to check if a given number (n) is a palindrome. i also used limits.h to identify if the number is

is exceeding the limit. i came up with this beut it's no good. any ideas? */

#include <iostream>

#include <stdlib.h>

#include <limits.h>

#include <math.h>


using namespace std ;

int main ()

{

int a, n, m=0, t ;

cout<<"Enter query number:"<<endl ;

cin>>n ;

t=n ;

  while (n)

    {

      {

       a=n%10 ;

       n=n/10 ;

       m=m*10+a ;

        {

         if (INT_MAX-n<a)

         cout<<"overload" ;

        }

      }

if (t==m)

  cout<<t<<"this number is already a palindrome"<<endl ;

else

  cout<<t<<"this number is not a palindrome"<<endl ;



    }

return 0 ;

}

One idea is to start by telling us what the program is and isn't doing right. Especially since aside from needing the output formatted better, this seems to do what you want.

Well, it's printing "not a palindrome" for all the numbers i punch
Including many palindromes..

you need to move the curly brace from line 60 to line 49 to put the if statement on line 50 outside your while loop.

I think you'll find that you're getting a number of not a palindrome statements, but if you look closely the last one will say it is a palindrome if it is one. Moving the curly brace,}, as was mentioned should clear that up.

The code works when I test it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.