0

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?

1

All of those exclamation makes are used to end a sentence. There will be no instances where one is used to not end a sentence, per the specification. Your problem is that sentences is declared as an int. You either need to declare it as a float or cast it to one before performing division with it because of how integer division works, chopping off anything beyond a decimal point. This will make your calculations end with unexpected results.

Hope this helps, but let me know if this doesn't solve your issue.

1
  • Solved ! Thanks again! Feb 26 at 16:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .