Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Sep 2009
    Posts
    16
    Thanks
    3
    Thanked 0 Times in 0 Posts

    having problems creating loop

    I am writing a program that will check whether or not specific text input is a palindrome or not.
    I'm a little stuck trying to fit in my loop while checking the text.
    Any help would be greatly appreciated.



    Code:
    #include<iostream>
    #include<string>
    
    using namespace std;
    
    int main()
    {
    char strn[80];
    cout<<"Please enter your text input: ";
    cin.getline(strn,80);
    int len=strlen(strn);
    int loop=0;
    
    
    bool palin=true; 
    
    for(int c=0;c!=len/2;c++) 
    {
    if(palin) 
    {
    if(strn[c]!=strn[len-c-1]) 
    {
    palin=false; 
    }
    
    }
    else
    {
    break; 
    }
    }
    
    
    
    if(palin)
    {
    cout<<"Your text input is a palindrome.";
    }
    else
    {
    cout<<"Your text input is not Palindrome.";
    }
    
    cin.get();
    return 0;
    
    	
    	}

  • #2
    Regular Coder BWiz's Avatar
    Join Date
    Mar 2006
    Location
    Sol System
    Posts
    471
    Thanks
    7
    Thanked 21 Times in 21 Posts
    Where exactly are you errors? Remember to consider your checking when you have an even amount of characters and an odd amount of characters.
    Last edited by BWiz; 10-01-2009 at 02:53 AM.
    BWiz :: Happy Coding!
    2006
    2007 2008 2009
    2010 2011
    Irrational numbers make no sense.

  • #3
    New Coder
    Join Date
    Sep 2009
    Posts
    16
    Thanks
    3
    Thanked 0 Times in 0 Posts
    there is no errors
    but i need to have the program loop over and over again in till you enter END to end the loop or in other words the string

  • #4
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,865
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    There was a similar thread at http://www.codingforums.com/showthread.php?t=177620 which might be helpful to you too.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •