the program seems to be running fine but I don't know what went wrong in the index, it just doesn't give the right answer.
#include <cs50.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
int main(void)
{
float L, S;//average number of letters and sentences per 100 words
string text;
int count_letters = 0, count_words = 0, count_sentences = 0;//number of letters, sentences and words
text = get_string("Text: ");//get user input
for (int i = 0; text[i] != '\0'; i ++)
{
if (isalpha(text[i]))//count letters
{
count_letters ++;
}
if (isspace(text[i]))//count words
{
count_words ++;
}
if (sentences[0][i] == '?' || sentences[0][i] == '!' || sentences[0][i] == '.')//count sentences
{
count_sentences ++;
}
}
printf("%i letter(s)\n", count_letters);
printf("%i word(s)\n", count_words + 1);
printf("%i sentence(s)\n", count_sentences);
L = (float)count_letters / /*(float)*/((count_words + 1) * 100);
S = (float)count_sentences / /*(float)*/((count_words + 1) * 100);
float index = (0.0588 * (L - 0.296) * (S - 15.8));//Coleman-Liau index
int answer = round(index);
if (answer > 16)
{
printf("Grade 16+\n");
}
else if (answer < 1)
{
printf("Before 1\n");
}
else
{
printf("Grade %i\n", answer);
}
printf("%i\n", answer);
}