Я делаю эту программу, которая предположительно будет действовать как программа, которая показывает уровень оценки чтения данного текста на основе индекса Коулмана-Ляу. До сих пор я правильно выполнил функции букв, счетчиков слов и предложений. Проблема в том, что, когда я включаю их в формулу индекса Коулмана-Ляу, результат не дает правильных ответов.
Я подозреваю, что допустил некоторые ошибки при толковании этого в формулу: L - среднее количество букв на 100 слов в тексте, а S - среднее количество предложений. за 100 слов в тексте. , как показано в моем коде ниже. Или, возможно, это как-то связано с тем, как я положил float перед буквами L и S?
Независимо от того, что я делаю, S всегда будет производить 0,000000 в результате.
#include <stdio.h>
#include <cs50.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
int main(void)
{
//ask for user input
char *text = get_string("Text: ");
//** letter counter function that prints the Letter-count in the text
//**build a word counter function and print the wordcount in the text
//**build a sentence counter function and print the sentence-count in the text
//Put everything into formula
float L = (letter_counter / word_counter) * 100.00;
float S = (sentence_counter / word_counter) * 100.00;
float index = (0.0588 * L) - (0.296 * S) - 15.8;
int rounded_index = round(index);
//If the index is greater than or equal to 16, then print Grade 16+
if (rounded_index >= 16)
{
printf("Grade 16+\n");
}
//If the index is less than 1, print before grade 1
if (rounded_index < 1)
{
printf("Before Grade 1\n");
}
//Else print the index given by the coleman-liau index computation above
else
{
printf("Grade %i\n", rounded_index);
}
}
Любые советы / предложения будут оценены. Спасибо.