Palindrome with loop

Trying to create a program to test if a word entered is a palindrome and if not to loop back for a secondary prompt. Using Visual C++ 2010, it runs with no error, but it infinitely loops the "Enter word:" prompt without pausing for the cin. My instructor looked over the code and is as confused as I am. The base program was done before, this is to add a loop to it. I've tried several different loop styles and they all wouldn't work, this one does but only loops the first cout.

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
  #include "StdAfx.h"
#include <iostream> 
#include <string> 

using namespace std; 

int main() 
{ 

	char str[100]; 
	int done=0;
	while(!done)
	cout << "Enter word :"; 
	cin >> str; 
	int x = strlen(str)-1; 
	for(int i = 0; i <= x; i++) 
	{ 
		if (str[i] == str[x-i]) 
		{ 
			continue; 
		} 
		else
		{ 
			cout<<"Not a palidrome"<<endl;
		} 
	} 

	cout << "Indeed Palidrome"<<endl; 
	done++;
	system ("pause");
	return 0; 
}
a) i would take off the "stdafx.h". i think there is an option to let you do this in vs, since you appear to be using nothing from it.

b) why are you using char *'s instead of std::string, especially since you included <string>.

c) i would use type bool instead of int for boolean operations. you shouldnt need to do that in c++ unless you want it to work with a c compiler

d) you forgot brackets around the while which is why it just keeps saying "Enter Word :";

e) i wouldnt use system() for anything.
A) Take out stdafx.h and it gives an error
B) The only problem with the program is with the loop itself, it's only looping the first line after the while, it works with char just fine so didn't want to change it.
C) I used the int for simplicity of the coding and it works just fine for me
D) Care to elaborate just which brackets I'm forgetting?
E) I used the system ("pause") to make it pause without terminating immediately upon code completion when running from the debug option.
like i said... there is a setting in vs that lets you remove it. i understand char[]s arent the problem. i said why are you using them when you included <string> and std::string works so much better than char[].

c) i understand it works fine... i never said it didnt. im saying use bool. that is what it is meant for. using int over bool for simplicity makes no sense, because bool is "simpler"
d) the brackets for the while loops... if you dont understand what i mean i suggest taking another look at loops. scroll down to while: http://www.cplusplus.com/doc/tutorial/control/

e) i understand what system(pause) does. i said it shouldnt be used. there are better ways of pausing.

also, line 29 is pointless, and i wouldnt use using namespace std. rather using std::object or std::object_when_called. and beyond those brackets, i never said any of your code was [b]wrong[b]. i just said there are better more c++ ways of doing it
A little bit of formatting might help to see the problem with the loop:
10
11
12
13
14
15
char str[100];
int done=0;
while(!done)
    cout << "Enter word :";
cin >> str;
int x = strlen(str)-1;
Topic archived. No new replies allowed.