Background: C noob here. I'm trying to tidy up a program that calculates the readability of a piece of text. To do this I'm using the Coleman–Liau index. I'm trying to build a function and pass 3 arguments, how many letters, words and sentences there are in the text.
Problem: Function doesn't handle variables as expected. I've included some print statements to see what's going on in the function
Function Declared below my main() function:
float Coleman_Liau_index(int words_, int letters_, int sentences_)
{
float L = (letters_ / words_) * 100;
printf("Average number of letters per 100 words %.2f\n", L);
float S = (sentences_ / words_) * 100;
printf("Average number of sentences per 100 words %.2f\n", S);
float index = 0.0588 * L - 0.296 * S - 15.8;
return index;
}
Implementation of function inside main() :
float words = spaces + 1;
printf("%i letter(s)\n", letter);
printf("%.0f word(s)\n", words);
printf("%i sentence(s)\n", sentences);
//Putting it all together - Coleman_Liau_index
float index = Coleman_Liau_index(words, letter, sentences);
Example Incorrect Output:
Average number of letters per 100 words 400.00
Average number of sentences per 100 words 0.00
Example of Desired Output:
Average number of letters per 100 words 421.43
Average number of sentences per 100 words 4.29