Jump to content

Welcome to Geeks to Go - Register now for FREE

Geeks To Go is a helpful hub, where thousands of volunteer geeks quickly serve friendly answers and support. Check out the forums and get free advice from the experts. Register now to gain access to all of our features, it's FREE and only takes one minute. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more.

Create Account How it Works
Photo

Palindrome detection


  • Please log in to reply

#1
Jodachua

Jodachua

    New Member

  • Member
  • Pip
  • 1 posts
I am working on this project: http://condor.stclou...cts/p11s06.html

I am having trouble with my palindrome function.... here is the code for the whole program... the code for the palindrome function is at the bottom:

#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <cctype>

const int N=80;

using namespace std;
void read(char x[], int& i);
void upper(char x[], int i);
bool palin(char x[], int i);

int main()
{
char x[N];
int i=0;

read(x,i);
upper(x,i);
if(palin(x,i))
{
cout<<"The string is a palindrome."<<endl;
}
else
{
cout<<"The string is NOT a palindrome."<<endl;
}

return EXIT_SUCCESS;

}

void read(char x[], int& i)
{
char ch;

cout<<"Enter a line that might be a palindrome:"<<endl;

cin.get(ch);
while ( ch >= ' ' )
{
if(isalpha(ch))
x=ch;
++i;
cin.get(ch);
}
}

void upper(char x[], int i)
{
char ch;
cin.get(ch);
for(int n=0; n<i; ++n)
{
ch = toupper(ch);
x[n]=ch;
}
}

bool palin(char x[], int i)
{
int leftch=0;
int rightch=i-1;

if(x[leftch]==x[rightch])
{
++leftch;
--rightch;
return true;
}
else
{
return false;
}
}

  • 0

Advertisements







Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP