Palindrom Function

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.

is there anyone who can help ?!!


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

// CheckingPalindrome.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include<iostream>
#include<string>
using namespace 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)
	return true;


	else if ( userword[x]== userword [x+len-1]  )
					
							return CheckPal( userword ,  x+1, len-2);
				

 else return false;

}

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.
Topic archived. No new replies allowed.