While counting the number of sentences ( Pset 2: Readability) , how do we differentiate between exclamation marks within a sentence and those which are used to end a sentence ?
This is my code:
//Count number of sentences
int sentences=0;
for(int k=0 ; k<n ; k++)
{
if(s[k]=='!'||s[k]=='?'||s[k]=='.')
sentences++;
}
printf("%i sentences\n",sentences);
//Calculate L and S
float L= ((letters/words)*100);
float S= ((sentences/words)*100);
//Use the Coleman-Liau index
int index= round((0.0588 * L) - (0.296 * S) - 15.8);
//Print the result
if (index>=16)
{
printf("Grade 16 +");
}
else if(index<1)
{
printf("Before Grade 1");
}
else
{
printf("Grade %i",index);
}
My output for one of the sentences given to check
Text : Congratulations! Today is your day. You're off to Great Places! You're off and away!
65 letters
14 words
4 sentences
Grade 8
But it is supposed to be Grade 3
I think this has to do with the exclamation marks,but how do I fix this logical error?