Thread: Strings Help

    #1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    1
    Rep Power
    0

    Lightbulb Strings Help


    I have a problem writing a program to check weather the string is palindrome, and to get the ASCII sum of the string.

    Any suggestion? C++ Visual Basic
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Location
    Whyalla, Australia
    Posts
    20
    Rep Power
    0
    Well, I'd just use strlen to find the length of the string, set one counter as the length and the other as 0, and loop through checking if each character matches.
  4. #3
  5. No Profile Picture
    Senior Slacker
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Location
    Houston, TX
    Posts
    30
    Rep Power
    12
    I think should do it.......

    PHP Code:
    #include <string>
    #include <iostream>
    using namespace std;

    int main(void)
    {
      
    string phrase;
      
    int ij;
      
    bool isPalindrome true;

      
    cout << "Please enter a phrase to check: ";

      
    getline(cinphrase);

      for(
    i=0j=phrase.length() - 1i<ji++, j--)
      {
        if(
    phrase[i] != phrase[j])
        {
          
    isPalindrome false;
          break;
        }
      }

      if(
    isPalindrome == true)
        
    cout << "This Was A Palindrome" << endl;
      else
        
    cout << "This Was NOT A Palindrome" << endl;

      return 
    0;

    Cya,

    Jim

IMN logo majestic logo threadwatch logo seochat tools logo