Recklein3
09-30-2009, 08:31 PM
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.
#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;
}
I'm a little stuck trying to fit in my loop while checking the text.
Any help would be greatly appreciated.
#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;
}