Need a Help in Arrays

Write here if you have problems with your C++ source code

Moderator: Board moderators

Post Reply
Salam
New poster
Posts: 3
Joined: Fri Dec 01, 2006 12:17 pm

Need a Help in Arrays

Post by Salam » Fri Dec 01, 2006 12:31 pm

Hello

i'm asked to Write a function, palindrome(

Salam
New poster
Posts: 3
Joined: Fri Dec 01, 2006 12:17 pm

Post by Salam » Fri Dec 01, 2006 1:24 pm

thank you very much if at least red the massage or not.
i solved the problem
but i'm still asking the first question
but the second i new that it does not need to use binary search but the question remain how i make the programe ignor the upper case??????????????????????

thanx

misof
A great helper
Posts: 430
Joined: Wed Jun 09, 2004 1:31 pm

Post by misof » Fri Dec 01, 2006 10:52 pm

#include <cctype>
and then take a look at functions like: tolower(), isalpha(), ...

Salam
New poster
Posts: 3
Joined: Fri Dec 01, 2006 12:17 pm

Post by Salam » Sun Dec 03, 2006 10:59 am

Thank you very much for help

still one thing remain ................how do i make the programe to notice the end of the input?????

my prog. as following:

Code: Select all

#include <iostream>
#include <string>
#include <cctype>

using namespace std;


void palindrome(int last,char f[],bool h);
int main()
{
	//declaring varibles
	char A[100];
	int i=0;
	int last;
	bool h;
	

	//asking the user to input
	cout<<"please enter a sentece to end it type a dot"<<endl;
	for(i=0;i<=100;i++)
	{
		
		
		cin>>A[i];
		A[i]=tolower(A[i]);
		if(A[i]==','||A[i]==' '||A[i]=='"'||A[i]=='!'||A[i]=='?'||A[i]==':'||A[i]==';')
			continue;
		else if(A[i]=='.')
			break;
	
	}
	last=i;

	//call the function
	palindrome(last,A,h);
	
	return 0;
}




//the function difinition
void palindrome(int last,char f[],bool h)
{
	for (int k=last;k>=0;k--)
		for(int j=0;j<last;j++)
		{
			if (f[k]==f[j])
				h=true;
			else 
				h=false;
		}
		if (h==true)
			cout<<"It is a palindrome"<<endl;
		else
			cout<<"It is not a palindrome"<<endl;
}



but the Question asks to ignor the punctuation so i need another condition.

jan_holmes
Experienced poster
Posts: 136
Joined: Fri Apr 15, 2005 3:47 pm
Location: Singapore
Contact:

Post by jan_holmes » Sun Dec 03, 2006 6:33 pm

If you want to make your program ends once it is done, just use :

Code: Select all

while (cin >> n) {
//process
}
or

Code: Select all

while (scanf("%d",&n) != EOF) {
//process
}
Hope it helps :wink:

Post Reply

Return to “C++”