Please help me in Palindrome Code(Arrays) Please

Hi I badly need your help im having a trouble creating this program this is the problem:

Input:
One or more words that may contain all possible characters – alphabet, number, space or any special
character.
Output:
Begin the program display with the message: “Enter word or enter 'Q' to quit.”
Mark the beginning of every input with “>> ”.
After each entry, there may be three possible outputs:
• Display “PALINDROME” if the word entered, disregarding cases, spaces and special
characters, is a palindrome.
• Display “NOT PALINDROME” if the word entered, disregarding cases, spaces and special
characters, is not a palindrome.
• Display “OOPS! Enter a word with at least two alphabetical/numeric characters” if the word
entered, disregarding cases, spaces and special characters, is less than two characters.
End the program if user entered the letter ‘Q’ regardless of the case and whether it has additional space or
special characters. (See next page for sample output and format.)

Please help me. Im a newbie at programming XD
Hello @waffle200 this is not complete but may help! ;D

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
//palindrome.cpp
//Program that evaluates if a word is palindrome -without disregarding cases-

#include <iostream>
using std::cout;
using std::cin;
using std::endl;

#include <string>
using std::string;
using std::getline;

bool isPalindrome(string word);
bool isEven(string word);

int main(){

string word;

cout<<"Enter a word: ";
getline(cin,word);

if(isPalindrome(word))
	cout<<word<<" is palindrome"<<endl;
else
	cout<<word<<" is not palindrome"<<endl;


return 0; //indicates success
}//end main

bool isEven(string word){
	if(word.size()%2==0)
		return true;
	else
		return false;
}//end function isEven

bool isPalindrome(string word){
	
	if(isEven(word)){ //if the number of letters in the word are even
		for(int i=0;i<(word.size()/2)-1;i++){
			for(int j=word.size()-1;j>(word.size()/2)-1;j--){
				if(word[i]!=word[j]) //if there are some difference is not
//palindrome
					return false;
			}//end inner for
		}//end outer for
	}else{ //if the number of letters in the word are odd
		for(int i=0;i<(word.size()/2)-1;i++){
                        for(int j=word.size()-1;j>(word.size()/2)+1;j--){
                                if(word[i]!=word[j]) //if there are some difference is not
//palindrome
                                        return false;
                        }//end inner for
                }//end outer for
	}//end if...else

return true;
}//end function isPalindrome



Eyenrique-MacBook-Pro:Study Eyenrique$ ./palindrome 
Enter a word: 131
131 is palindrome
Eyenrique-MacBook-Pro:Study Eyenrique$ ./palindrome 
Enter a word: Hello
Hello is not palindrome
Eyenrique-MacBook-Pro:Study Eyenrique$ ./palindrome 
Enter a word: SOS
SOS is palindrome
Eyenrique-MacBook-Pro:Study Eyenrique$ ./palindrome 
Enter a word: civic 
civic is palindrome
Eyenrique-MacBook-Pro:Study Eyenrique$ ./palindrome 
Enter a word: kayak
kayak is palindrome
Last edited on
Sir. Thank you for the code I think this might help me as well :D

Btw sir. Just one question how can you say that your code is not complete?
Just wondering XD.

Sir my prof in programming told me that this should be the ouput: (See Link)
http://prntscr.com/1tecox

And sorry sir but I dont really have the idea on how to make the code for this program. Mind giving me the base code? XD Thanks sir :)
Last edited on
closed account (3qX21hU5)
You should have all the code you need from the example that eyenrique posted. He actually gave you a full program for your assignment. I would suggest studying how his program works and making sure you understand it yourself.

That way you can edit the output to match the way it is suppose to be on your own. Remember if others do the hard work for you you won't learn a thing. Programming is problem solving plain and simple. If you can't problem solve you better learn quickly how to.
Hmm. I understand all sir except for that bool thing. XD Im only at programming class 1 XD maybe my teacher wont accept this kind of code cause she doesnt teach bool to us XD
closed account (3qX21hU5)
I am quite confused how your teacher expects you to create a palindrome program when she hasn't even taught you about basic types which should be learned on day one.

But anyways a bool is a boolean variable. It can either holds true or false. It is quite simple actually. So in the program above he is returning true if it is a palindrome and false if it is not.

Anyways if you understand everything but the bool you should be able to easily transfer that knowledge and create a solution for your assignment that your teacher will accept.

Wish you the best of luck and if you have any questions feel free to post them here and we would be glad to help you. But realize that we are here to help you learn how to do it yourself not do it for you.

Last edited on
Thanks sir. Im studying the code right now. Thanks to sir eyenrique and to you sir Zereo ^_^
Topic archived. No new replies allowed.