Thread: Palindrome Assignment

  1. #1
    Registered User
    Join Date
    Apr 2009
    Posts
    6

    Palindrome Assignment

    I am honestly completely lost and could use any help i can get.

    Code:
    #include <iostream>
    #include <stdlib.h>
    #include <string.h>
    #include <math.h>
    
    using namespace std;
    
    int string;
    int create;
    int check;
    char n;
    bool done;
    bool reverse;
    
    
    int main()
    {
        int choice;
        int myString;
        {
        cout << "***Welcome To The PALINDROME GAME!***";"\n";
        cout << "Choose which function you would like to run.";"\n\n";
        cout << "1)Check to see if a word is a palindrome.";"\n";
        cout << "2)Make a palindrome.";"\n";
        cin << choice;
          {
              if choice==1
                 (cout << check);
                 else
                     (cout << create);
    
    		               char myString[10];
    	                	cin >> myString;
    		
    
                          int n[10] = {0,1,2,3,4,5,6,7,8,9};
                               n[0] = 1;
                                n[1] = 2;
                                 n[2] = 3;
                                  n[3] = 4;
                                   n[4] = 5;
                                    n[5] = 6; 
                                     n[6] = 7; 
                                      n[7] = 8; 
                                       n[8] = 9; 
                                        n[9] = 10;
    		
          }
        }
    }
    
        int create()
        {
            cout << "Please enter a string to be checked for palindromeness";
            cin >> string;
            cout << reverse;
            
            if string==reverse
              cout << "HOORAY! IT IS A PALINDROME!";
              else 
                   cout << "BOOOOO! IT IS NOT A PALINDROME!";
            
        
        }
        
       /* int check()
        {
        }
        */
        
        
        
        bool reverse()
        {
             
            cout << myString[9] << myString[8] << myString[7];
    		cout << myString[6] << myString[5] << myString[4];
            cout << myString[3] << myString[2] << myString[1] << myString[0];
        }


    i will probably have to end up redoing the whole code, i am seriously completely lost

    any help or suggestions greatly appreciated!

    (here are the requirements of the assignment:


    Palindrome
    Has both a “check” and “create” palindrome function

    Uses arrays of characters

    Does not contain extraneous library headers

    Formatted and commented correctly

    Extra Credit
    Can remove characters from a string that is not a palindrome (from “check” function)

  2. #2
    Registered User BuzzBuzz's Avatar
    Join Date
    Feb 2009
    Posts
    89
    Have you been able to write a small program that takes a word and reverses it? That is where I would start, and then work on comparing the original with the reversed to see if they are the same.

    Also you shouldn't need the C header files, you should be able to do it with C++ headers.
    Any help I give may be classified as:
    The Blind leading the Blind...
    Currently working through:
    "C++ Primer Plus"

  3. #3
    Registered User
    Join Date
    Apr 2009
    Posts
    6

    Okay

    alright, ill try that

    thanks.

  4. #4
    Registered User Cpro's Avatar
    Join Date
    Oct 2006
    Posts
    149
    The method BuzzBuzz suggested is probably the best way to go about it. But, just to give you another option...
    You could have the word stored in an array, and compare the characters until all have been compared. Something like:

    myString[0] == myString[n-1]
    myString[1] == myString[n-2]
    myString[2] == myString[n-3]
    ...
    n is the size of the array.

    So, you continue this process until all letters have been checked. If they all equal the opposite one, then it is a palindrome. Notice that you would have to address the issue of an even vs odd length array/word. In the case of odd length, the middle letter wouldn't be compared to any other.
    IDE - Visual Studio 2005
    Windows XP Pro

  5. #5
    Registered User BuzzBuzz's Avatar
    Join Date
    Feb 2009
    Posts
    89
    Quote Originally Posted by Cpro View Post
    The method BuzzBuzz suggested is probably the best way to go about it. But, just to give you another option...
    You could have the word stored in an array....
    This is a very proud moment for me, I've actually posted something that is correct!

    Although the way that I would do this involved using reverse and then an if statement to compare, Cpro is closer to what the assignment is actually asking for by using an array.

    Quote Originally Posted by chrryslurpeeboi View Post

    Palindrome
    Has both a “check” and “create” palindrome function

    Uses arrays of characters
    I'm not sure about the requirement to create a palindrome, check is easy as you're checking the input, but what are supposed to create a palindrome from? That requirement is really too vague (unless I missed something....again).
    Any help I give may be classified as:
    The Blind leading the Blind...
    Currently working through:
    "C++ Primer Plus"

  6. #6
    Registered User
    Join Date
    Apr 2009
    Posts
    6
    The assignment is asking that you check to see if an entered palindrome is actually a palindrome (so it has to check if it the same fowards as backward)--check

    And create is to just reverse the order of the characters in the array

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Error in Recursive String Palindrome Code
    By clegs in forum C Programming
    Replies: 13
    Last Post: 12-21-2008, 12:36 PM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  3. Replies: 1
    Last Post: 10-27-2006, 01:21 PM
  4. Just finished assembly assignment
    By xddxogm3 in forum Tech Board
    Replies: 6
    Last Post: 10-08-2005, 04:01 PM
  5. Palindrome Coding trouble
    By TheLoneWolf32 in forum C++ Programming
    Replies: 3
    Last Post: 02-22-2003, 07:05 PM