473,398 Members | 2,120 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Palindrome

I just wanted to know how can i remove spaces and punctuation from a user input. I've return the program for palindrome and it works for words but not for phrases with spaces and pnctuation. so far i've got the following program

#include<iostream>
#include<string>
#include<cctype>

using namespace std;

int main(void)
{

string phrase, reverse, phrase1;
short i;

cout << " Welcome to the Palindrome detection Program.\n\n";

cout << "Please enter your phrase: ";
getline(cin, phrase);

for(i = 0; i != phrase.length(); i++)

{

phrase1 = (char) tolower(phrase[i]) + phrase1;

}

for(i = 0; i != phrase.length(); i++)

{

reverse = (char) tolower(phrase[i]) + reverse;

}

cout << reverse << "\n\n";

cout << "\n\nThe phrase you entered is "
<< (phrase1 == reverse ? "a Paliindrome.\n\n"
: "not a Palindrome.\n\n");

return 0;

}
May 7 '07 #1
3 1982
Ganon11
3,652 Expert 2GB
Loop through the string character by character - if a character is either a space or punctuation, remove it. You can do this by using the .substr() method to retrieve the string before the current character and the string after the current character, then concatenating the two strings back into the original string.
May 8 '07 #2
Loop through the string character by character - if a character is either a space or punctuation, remove it. You can do this by using the .substr() method to retrieve the string before the current character and the string after the current character, then concatenating the two strings back into the original string.

if u don't mind can u plz. give me a little example, cause i don't understand what u mean by that
May 8 '07 #3
arunmib
104 100+
if u don't mind can u plz. give me a little example, cause i don't understand what u mean by that

What i would try is the following,

Expand|Select|Wrap|Line Numbers
  1. for(i = 0; i< phrase.length(); i++)
  2. {
  3.      if( (phrase[i] >97) && (phrase[i] >122) )
  4.              cout << phrase[i];
  5. }

The above code filters out whatever you type and just prints lowercase characters (a to z)
May 8 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Lorin Leone | last post by:
Can anyone help me modify the program so that it recognizes strings like "Anna" as palindromes. To make the program "case-insensitive." using the built-in C++ function "toupper". and so that it...
23
by: Amar Prakash Tripaithi | last post by:
Dan Hoey, who had recently graduated, wrote a C program to look for and construct the following beauty: A man, a plan, a caret, a ban, a myriad, a sum, a lac, a liar, a hoop, a pint, a catalpa,...
32
by: ramakrishnadeepak | last post by:
HI Everybody, I 've to submit a program on c.Can any one help me plz.........The problem is like this:: Write a program which computes the largest palindrome substring of a string. Input:...
4
by: outofmymind | last post by:
hi, im trying to solve the following question: Create a class responsible for determining whether a string is a palindrome. Show your test cases. Palindome mypal("bob"); ...
3
by: colinNeedsJavaHelp | last post by:
I am still having an exceptional amount of trouble with java. This is my new assignment, if anyone can help I would greatly appreciate it. I don't even know where to start. A word or phrase in...
2
by: Synapse | last post by:
aloha people! I need help in my java palindrome program. It's a 5-digit palindrome checker. The code below is running good but i got a few problems on it. If I enter 33633, 11211, 45554, it will...
20
by: Wabz | last post by:
Hello mates, Does anyone know how to write a function that tests if an integer is a palindrome in C language?
4
by: vicestner | last post by:
Write a Java program that prints the longest palindrome in an input file to standard output. A palindrome is a string whose reverse is the same as the original. Ignore case, whitespace, and...
5
by: rubyhuang | last post by:
i'm a new perl learner, this is the first perl task i will do. please help me. The user can input a string, and then a script will check to see if the string is a palindrome or not, displaying the...
2
by: bigtd08 | last post by:
help writing this palindrome program for my c++ class. HERE WHAT THE CODE SHOULD BE LIKE. Write a program that takes a line of input from the keyboard and check to see if that line is a palindrome....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.