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.
int sentenceNumber(string paragraph)
{
string sentence;
unsignedint 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.