Count sentence.

Write your question here.
Hello all,
I have a homework which is counting sentence based on the dots you plugged in but my program only count the sequence of the first dot instead counting all dots i will paste my code below and according to the rules, using char function is illegal. Thanks for your helping.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
  int sentenceNumber(string paragraph)
{
	string sentence;
	unsigned int i = 0, length; // i stands for index
	length = paragraph.length();
	int position = 0;
	while (i < length )
	{
		i = paragraph.find(".", i);
		if (i != string::npos)
		{
			sentence = paragraph.substr(position, i);
			cout << sentence;

			i += 1;
			position = i;
		}
	}
	return length;
}
The function returns the length of the string not the number of dots. You need a count variable you increase each time the if condition (line 10) is true.
Topic archived. No new replies allowed.