string delete

I am having trouble with my homework. The loop is not stopping inside the function.
Here is what I have:

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
#include <iostream>
#include <string>
using namespace std;
#include <fstream>




string stringLD(string); // Function that left deletes characters in a word 

int main () 
{
	int num;      // variable for how many words to process
	string word;  // 
	fstream inFile;
	   
	   inFile.open("StringLD");
	   cout << "Please enter number of words to call \n";   // Validates user's input
       inFile >> num;

	    if (num>0 && num<=100)
		{
		  cout << num << endl;
		}
		  
		 for (int count=0;count<=num; ++count )
		 {
	       cout << "Please enter word  " << (count+1) << endl;
	       inFile >> word;
		   word=stringLD(word);
		   
		 }
		   
		 
		

			 system ("pause");return 0;
	}	

string stringLD(string word) 
{
  do
	{
	    word.erase(0,1);
		cout << word << endl;
	}while(word.length()!=0 || word.compare(word)!=0);
	   
	 
    return 0;
}


Here is what my homework assignment wants me to do?
Stringld(left delete) is a function that gets a string and deletes its leftmost character (for instance
Stringld(``acm") returns ``cm").
You are given a list of distinct words, and at each step, we apply stringld on every word in the list. Write a
program that determines the number of steps that can be applied until at least one of the conditions become
true:
1. A word becomes empty string, or
2. a duplicate word is generated.
For example, having the list of words aab, abac, and caac, applying the function on the input for the first
time results in ab, bac, and aac. For the second time, we get b, ac, and ac. Since in the second step, we
have two ac strings, the condition 2 is true, and the output of your program should be 1. Note that we do not
count the last step that has resulted in duplicate string. More examples are found in the sample input and
output section.
Don't mix tabs and spaces.
for (int count=0;count<=num; ++count ) // too long
1
2
3
4
5
string stringLD(string word) {
  //...
  return 0; //eh? since when 0 is a string?
}
word.compare(word)!=0; //false 

You are just clearing every string. You need a container for all the strings and compare against all.
What are the limits for this problem?
Topic archived. No new replies allowed.