/*This program allows the user to choose between the option of determining if the word, phase, and/or sentence
is a palindrome or comparing two integers to see the number of equvilent integers entered at runtime.
*/
#include <iostream>
#include <iomanip>
#include <fstream>
#include <cstring>
#include <string>
usingnamespace std;
void showMenu();
void showChoices(double);
//This allows the string to center characters to the center.
//Also this is where you clairfy what the functions are.
void center(string);
bool YPalindrome(char* Palindrome);
int i;
int main()
{
int FPint [10] = {i};
int SPint [10] = {i};
char FPalindrome [256];
bool PDrome_check;
double choices;
constdouble PDrome = 1, TwoInt = 2, Close_Program = 3;
//This code allows to digits after the decimal point.
cout << fixed << showpoint << setprecision(2);
do
{
system("cls");
showMenu();
cin >> choices;
while (!(choices >= PDrome) || !(choices <= Close_Program))
{
cout << endl;
center("OOpps!! Invaild Option");
cout << endl;
center("Please Re-Enter your choice: ");
cin.clear();
fflush(stdin);
cin >> choices;
}
//These if statements goes through the options and once an option is chosen then the operation is taken.
if (choices == 1)
{
cout << "Enter a word, phase, or sentence: ";
cin >> FPalindrome;
PDrome_check = YPalindrome(FPalindrome);
if(PDrome_check == true)
{
cout << "Bingo! Yes, It's a Palindrome!";
}
else
{
cout << "Nope! That's not a Palindrome.";
}
cin.clear();
fflush(stdin);
fflush(stdin);
cout << endl << endl << endl;
center("Press the Enter key to continue.");
cin.get();
}
elseif (choices == 2)
{
cout << "Enter the First positive integer: ";
cin >> FPint[10];
cout << "Enter the Second positive integer: ";
cin >> SPint[10];
cout << endl;
cout << "Number 1: " << FPint[10] << endl;
cout << "Number 2: " << SPint[10] << endl << endl;
for (int i = 0; i <= FPint[10]; i++)
{
if (FPint [i] == SPint [i])
{
cout << FPint [i] << " <---> " << SPint [i] << " <Bingo!>" << endl;
}
else
{
cout << FPint [i] << " <---> " << SPint [i] << endl;
}
}
fflush(stdin);
cout << endl << endl << endl;
center("Press the Enter key to continue.");
cin.get();
}
}
while (choices != Close_Program);
fflush(stdin);
cout << endl << endl << endl;
center("Program was created by Tan Nguyen.\n");
cout << endl;
center("Press Enter key to end the Program.");
cin.get();
return 0;
}
//This function shows the menu presented at the beginning.
void showMenu()
{
cout << endl;
center(" Menu\n");
cout << endl;
center("=~=~=~=~=~=~=~=~=~=~=~=");
cout << endl << endl;
center("1 Palindrome ");
cout << endl;
center("2 Compare Two Integers ");
cout << endl;
center("3 End the Program. ");
cout << endl << endl;
center( "Please Enter your choice: ");
}
// This portion is a function that sets a center for certain strings.
void center(string screen)
{
int value = (80 - (screen.length())) / 2;
for (int i = 1; i <= value; i++)
cout << " ";
cout << screen;
}
bool YPalindrome(char* Palindrome)
{
char* front;
char* rear;
front = Palindrome;// starts at the left side
rear = (Palindrome + strlen(Palindrome)) - 1;//starts at the right side, plus the incriment
while (front <= rear)
{
if ((*front) == (*rear) || (isspace(*front) || (isspace(*rear))))
{
do
{
front++;
} while((' ' == *front) || (ispunct (*front)));
do
{
rear--;
} while((' ' == *rear) || (ispunct (*rear)));
}
elseif(!(*front == *rear))
{
if ((' ' == *front) || (ispunct (*front)))
{
front++;
}
if ((' ' == *rear) || (ispunct (*rear)))
{
rear--;
}
else
{
returnfalse;
}
}
else
{
returnfalse;
}
}
returntrue;
}
You are advancing front and rear regardless of whether or not one of them is a character that you don'tdo wish to have influence if the string is interpreted as a palindrome when either one is a space, and you are not accounting for punctuation where you need to.
I edited the part with your code but it stills doesn't seem to accept capital letters and spaces well it accepts the capital letter at the beginning but when i put a space like (Ra cecar) it doesnt say that it is a palindrome