Function to check for palindrome

This is a discussion on Function to check for palindrome within the C++ Programming forums, part of the General Programming Boards category; Code: bool isPalindrome(bitset<8> bits); { bool palindrome = true; bitset<Max> b = bits; for(int i = 0; i < Max/2 ...

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    34

    Function to check for palindrome

    Code:
    bool isPalindrome(bitset<8> bits);
    {
        bool palindrome = true;
        bitset<Max> b = bits;
        for(int i = 0; i < Max/2 - 1; i++) { 
            if(b[i] ^ b[Max-1-i]) {
                palindrome = false;
                break;
            }
        }
        return palindrome;
    somethings off with this code and this is my first time dealin with bitset?

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,488
    Something like the extra ; at the end of the first line, or something like the missing closing brace.

    Or something else?

    Have you tried single-stepping the code with a debugger (for example).
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Mar 2012
    Posts
    1
    you are missing a curly bracket/brace at the end, to close the functions definition.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Palindrome function fun
    By SirSig in forum C Programming
    Replies: 4
    Last Post: 10-31-2011, 07:05 AM
  2. Palindrome Function
    By italia4fav in forum C Programming
    Replies: 4
    Last Post: 01-27-2011, 04:59 PM
  3. Help me check my hash function
    By lancetky in forum C Programming
    Replies: 23
    Last Post: 04-17-2010, 05:54 PM
  4. HELP W/ Palindrome function!!??
    By riley03 in forum C++ Programming
    Replies: 7
    Last Post: 10-14-2002, 06:47 PM
  5. palindrome function
    By Unregistered in forum C++ Programming
    Replies: 4
    Last Post: 03-12-2002, 08:45 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21