So, I think function 'round' in one case does rounding to the Grade 8, instead of Grade 7. But, if I remove it, another text getting wrong grade. in both cases the grade of either one text is wrong. What should I fix?
# include<stdio.h>
# include<cs50.h>
# include<string.h>
# include<ctype.h>
# include<math.h>
int main(void)
{
string text = get_string("Text: ");
int let = 0;
for (int i = 1, n = strlen(text); i < n; i++)
{
if ((text[i] >= 'a' && text[i] <= 'z') || (text[i] >= 'A' && text[i] <= 'Z'))
{
let++;
}
}
int words = 0;
for (int j = 1, n = strlen(text); j < n; j++)
{
if (text[j] == ' ')
{
words++;
}
}
int sent = 0;
for (int k = 1, n = strlen(text); k < n; k++)
{
if (text[k] == '.' || text[k] == '!' || text[k] == '?')
{
sent++;
}
}
float L = (let * 100) / words;
float S = (sent * 100) / words;
int index = round(0.0588 * L - 0.296 * S - 15.8);
if (index < 1)
{
printf("Before Grade 1\n");
}
else if(index > 16)
{
printf("Grade 16+\n");
}
else
{
printf("Grade %i\n", index);
}
}
Here is my program
[