Jump to content

Welcome to Geeks to Go - Register now for FREE

Need help with your computer or device? Want to learn new tech skills? You're in the right place!
Geeks to Go is a friendly community of tech experts who can solve any problem you have. Just create a free account and post your question. Our volunteers will reply quickly and guide you through the steps. Don't let tech troubles stop you. Join Geeks to Go now and get the support you need!

How it Works Create Account
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