View Single Post
Old Nov 30th, 2006, 4:50 PM   #1
fhslacrosse13
Newbie
 
Join Date: Oct 2006
Posts: 25
Rep Power: 0 fhslacrosse13 is on a distinguished road
my loop exits early

I'm working on a program that reads in a line of text from the user and then runs a free function(palidrome) to see if the text entered in a palidrome. The loop should prompt user for line of text then run palidrome which returns a bool, tell the user if it is a palidrome, then askes the user for another line of text until <ctrl-z> is entered. for some reason it askes for the palidrome and then exits. Can't figure it out.

int main(){
	myQueue<char> Q;
	myStack<char> S;
	char ch;
	cout<<"Enter lines of text - enter <ctrl-Z> to quit: "<<endl;
	cin.get(ch);
	while(ch!='\n'){
	while(cin){
		if(!isspace(ch)){
			Q.push(ch);
			S.push(ch);
		}
		if(palindrome (S,Q))
			cout<<"Palindrome!"<<endl;
		else
			cout<<"Not Palindrome"<<endl;
	}
		cout<<"Enter lines of text - enter <ctrl-Z> to quit: "<<endl;
		cin.get(ch);
	}
	return 0;
}
fhslacrosse13 is offline   Reply With Quote