I've tried everything but I can't figure out the bug in my code.
Getting the user inupt and counting the letters
int main(void)
{
int letters = 0;
//Getting user input
string text = get_string("Text: ");
//Counting the letters
for (int i = 0; i < strlen(text); i++)
{
if (isalpha(text[i]))
{
letters++;
}
}
counting the words and the sentences
int words = 1;
//Checking the spaces and counting the words
for (int i = 1; i < strlen(text); i++)
{
if ((isspace(text[i])) && (isalpha(text[i+1])) )
{
words++;
}
}
int sentences = 0;
//Checking the symbols and counting the sentences
for (int i = 0; i < strlen(text); i++)
{
if (text[i] == '.' || text[i] == '!' || text[i] == '?')
{
sentences++;
}
}
And then applying the formula
double L = 100.0 * letters / words;
double S = 100.0 * sentences / words;
double index = 0.0588 * L - 0.296 * S - 15.8;
int trueIndex = round(index);
if (trueIndex >= 1 && trueIndex <= 16)
{
printf("Grade %i\n", trueIndex);
}
else
{
if (trueIndex < 1)
{
printf("Before Grade 1\n");
}
if (trueIndex > 16)
{
printf("Grade 16+\n");
}
}
}
It gives me this error: expected "Grade 8\n", not "Grade 9\n". I know it has something to do with how I handled floats but I don't understand what's wrong