The indexes come out sometimes too low,some times too high and I don't really understand why if the variable calculations come out right every time.

Here's my code for it:

//calculates average letters per 100 words
float L = (((float)letters * 100.0) / (float)words);

//calculates average sentences per 100 words
float S = (((float)sentences * 100.0) / (float)words);

// calculates the index
float index = (0.0588 * L) - (0.296 * S) - 15.8;

Any help is greatly appreciated.

1 Answer 1


It looks like there's a step missing in the calculation. The final result is supposed to be rounded to the nearest integer. That would explain being just a little off in both directions.

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

  • Even if I round up, I keep getting a wrong answer as given by the problem's expected results, I get grade three when I'm supposed to get grade 2 etc. Sep 2, 2020 at 16:44
  • 1
    Are you sure that the code is counting the correct number of letters, words and sentences? Without seeing the rest of the code, I'm just guessing now.
    – Cliff B
    Sep 2, 2020 at 16:47
  • It was not. I forgot to count the first word which is always preceded by no spaces. Words always start at 1 Sep 2, 2020 at 17:29

You must log in to answer this question.

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