blackdove 0 Light Poster

:confused: This is my first recursion project and i have no idea if i'm even going about it the right way...It's a palindrome checker, which checks for integers. I can't check it character by character as a string. It compiles clean but when i execute it i get weird results like "4280412". It is supposed to display "yes" or "no"

here is my code: could someone please help me figure out or tell me what i'm doing wrong?

void CLab13Dlg::OnClear() //button that clears both edit boxes
{
    SetDlgItemText(IDC_NUMBER, "");
    SetDlgItemText(IDC_PALINDROME, "");
}

void CLab13Dlg::OnCheck() //button to check if integer is a palindrome
{
    GetDlgItemText(IDC_NUMBER, m_number);
    int length = m_number.GetLength(); //length of the string
    int number = atoi(m_number);
    palindrome(number, length);
    if(palindrome(number,length)==true)
    {
        m_palindrome.Format("%d", "Yes");
        SetDlgItemText(IDC_PALINDROME, m_palindrome);
    }
    else if(palindrome(number, length) == false)
    {
        m_palindrome.Format("%d", "No");
        SetDlgItemText(IDC_PALINDROME, m_palindrome);
    }
}

bool CLab13Dlg::palindrome(int number, int length)
{
    int value = (int)pow(10, length-1);
    if(length == 1)
    {        
        return(true);
    }
    else if(number/value == number%10)
    {
        number = number%value;
        number = number / 10;
        length= length - 2;
        palindrome(number, length);
        return(true);
    }
    else 
    {
        return(false);
    }
}
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.