This question comes from myprogrammming lab .
"Consider this data sequence: "fish bird reptile reptile bird bird bird mammal fish". Let's define a SINGLETON to be a data element that is not repeated immediately before or after itself in the sequence. So, here there are four SINGLETONs (the first appearance of "fish", the first appearance of "bird", "mammal", and the second appearance of "fish"). Write some code that uses a loop to read a sequence of words, terminated by the "xxxxx". The code assigns to the variable n the number of SINGLETONs that were read. (For example in the above data sequence it would assign 4 to n). Assume that n has already been declared but not initialized . Assume that there will be at least one word before the terminating "xxxxx"."
1 2 3 4 5 6 7 8 9
n = 0 ; // n will hold the amount of singletons
string x ; //assigns the string to x
do
{
cin >> x ; //inputs x
if (x != x) // checks to see if x has been repeated
n++ ; // if x has not been repeated the it increases the count by 1
} while ( x != "xxxxx" ); // designates a sentinel value to terminate the loop
cout << n ;
My value of n is still 0 , I can not figure out why.