A Plaindrome is a work, number or sentence that can be read the same from Left-Right and Right-Left
Numerical: 36763
Word: civic
Sentence: Fall Leaves When Leaves Fall.
You are asked to write a c++ program that prompts the user to enter a number, word, or sentence and the program checks if it is a palindrome or not using a recursive function. Validation is needed to ensure that the user has entered the input in a correct format
for example: 36v63 is not a palindrom
Thats what i wrote so far and it is running but my problem is how to make a vlidation condition so when the user enters an int(or anything other than char), the program gives him erorr message.
// CheckingPalindrome.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include<iostream>
#include<string>
usingnamespace std;
bool CheckPal(string,int,int);
int _tmain(int argc, _TCHAR* argv[])
{
string word;
cout<<"Entee Your Word U want to be checked" <<endl;
cin>>word;
int len=word.length();
for(int i=0 ; i <len ; i++)
{cout<<"hhh"<<endl;
cin>>word;}
if(CheckPal(word,0,len))
cout<<"It is a Palindrome"<<endl;
else cout<<"It is not a palindrome"<<endl;
return 0;
}
bool CheckPal(string userword , int x ,int len)
{
if (len<=1)
returntrue;
elseif ( userword[x]== userword [x+len-1] )
return CheckPal( userword , x+1, len-2);
elsereturnfalse;
}
ASCII characters are represented by numbers. Look up an ascii chart to see what numbers represent 0-9, then compare each character to see if it is in the range. if 48 <= x <= 57, then it is a number. You might also look at the cstdlib, it might help as well.