HELP W/ Palindrome function!!??

This is a discussion on HELP W/ Palindrome function!!?? within the C++ Programming forums, part of the General Programming Boards category; I know that you guys are all probably Palindromed out but I wrote a program and it's telling me that ...

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    21

    HELP W/ Palindrome function!!??

    I know that you guys are all probably Palindromed out but I wrote a program and it's telling me that m is an undeclared identifier and also a unreferenced local varibale errors....any idea on how to fix it??
    Code:
    #include <iostream>
    #include <string>
    using namespace std;
    //PROTOTYPE
    
    string Reverse(string s, int m);   //reverse s from
    bool IsPalindrome(string s); // Checks if it is Palindrome
                   
    // MAIN PROGRAM
    int main ()  {
    string word;
    string s;
    int m;
    	
    cout << " What word would you like to test to see if it is a Palindrome?"<< endl;
          cin >> word;
    
    string Reverse(); 
    bool IsPalindrome();
    	
    	
    	return 0;
    
    }
    //IMPLEMENTATION OF PROTOTYPE
    string Reverse(string s, int m) {
    
        string t = "";  //null string          
         int strlength=s.length(); 
        if (m == s.length()-1){
    
        return t+s[s.length()-strlength];  //the iterator takes the place of the '1'          
    
        } else {                                   
    
                  return s[s.length()-m-1] + Reverse(s, m+1); // recursive call
    
    	}          
    }                                     
    
    bool IsPalindrome(string s) {
    
    	string Reverse(string s, int m);
    		if ( Reverse( s,  m) == word){
    			return true;
    		}
    		else {
    			return false;
    		}
    }
    [edit]Code tags added by Hammer

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    string Reverse();
    bool IsPalindrome();


    You are calling your functions incorrectly:
    1) Don't specify the return type when you call them.
    2) Do provide the correct argumetns to them when you call them.
    3) Do check the return value to see if they did what you want them to.

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Veni Vidi Vice
    Join Date
    Aug 2001
    Posts
    343
    Use code tags when posting code
    Read This

  4. #4
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    I am posting this because you did not use code tags on this thread. In the furture please use Code Tags. They make your code MUCH easier to read and people will be much more likely to help you if you do. And they'll be happy about helping you


    For example:

    Without code tags:

    for(int i=0;i<5;i++)
    {
    cout << "No code tags are bad";
    }

    With Code Tags:
    Code:
    for(int i=0;i<5;i++)
    {
         cout << "This code is easy to read";
    }
    This is of course a basic example...more complicated code is even easier to read with code tags than without.

    I've added code tags for you this time. They can be added by putting [code] at the beginning of your code and [/code] at the end. More information on code tags may be found at the link in my signature. Any further questions or ways I can help please feel free to PM me.

    Good Luck,
    Hammer
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  5. #5
    Registered User
    Join Date
    Feb 2002
    Posts
    21
    So you mean where I have

    bool IsPalindrome & string Reverse in the main just have
    IsPalindrome and Reverse...

    your 2 and 3 points I am a little shaky on- can you elaborate a little....Do you mean that there needs be code b/t the two functions. I am new at this and my teacher talks in circles..I am a little confused.....I am not trying to be stupid......=)

  6. #6
    Registered User
    Join Date
    Feb 2002
    Posts
    21
    Sorry guys I try to use those code tags and just when I think I post it clear I get hammered with ***code tags**** =) Again, I am sorry!!!

  7. #7
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Your main() might look something like this:
    Code:
    int main(void)
    {
        string  word;
    
        cout << " What word would you like to test to see if it is a Palindrome?" << endl;
        cin >> word;
    
        if (IsPalindrome(word))
            cout <<word <<" is a palindrome." <<endl;
        else
            cout <<word <<" is not a palindrome." <<endl;
    
        return(0);
    }
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  8. #8
    Registered User
    Join Date
    Feb 2002
    Posts
    21
    Ok that helps a lot!! Thank you!!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Undefined Reference Compiling Error
    By AlakaAlaki in forum C++ Programming
    Replies: 1
    Last Post: 06-27-2008, 11:45 AM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  3. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 10:03 PM
  4. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 01:53 AM
  5. Question..
    By pode in forum Windows Programming
    Replies: 12
    Last Post: 12-19-2004, 06:05 PM

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