|
-
Sep 25th, 2002, 05:07 AM
#1
Thread Starter
Lively Member
this code could be shorter . . .
something tells me this code could be shorter.
can anyone suggest a shorter algorithm?
//Allows user to enter a word, then displays whether or not the word is a palindrome (same forwards and backwords)
#include <iostream.h>
#include <apstring.h>
void main()
{
apstring word;
int a,c,e;
cout<<"Enter a word: ";
cin>>word;
a=word.length();
a--;
for (c=0;c<a;c++)
{
if (word[c]!=word[a])
{
cout<<"That word is not a palindrome."<<endl;
e=-1;
c=a+5;
}
a--;
}
if (e!=-1)
cout<<"That word is a palindrome."<<endl;
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|