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.)
//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)
returntrue;
elsereturnfalse;
}//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
returnfalse;
}//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
returnfalse;
}//end inner for
}//end outer for
}//end if...else
returntrue;
}//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
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
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.