I replaced semicolon with a coma as sugested erlier. I compile the code but when I enter the text to receive Grade 3 nothing happens, again anny sugestion. Thanks.
#include <cs50.h> #include <stdio.h> #include <string.h> #include <math.h> #include <ctype.h>
int main(void) { //Get user input to count text input string s = get_string("Text: ");
int count_letters = 0;
int count_words = 0;
int count_sentences = 0;
//Count number of letters uper and lower case, words and centences
for (int i = 0, n = strlen(s); i < n; i++)
{
if (isalpha(s[i]))
{
count_letters++;
}
if (s[i] == '!' || s[i] == '?' || s[i] == '.')
{
count_sentences++;
}
if ((i = 0 && s[i] != ' ') || (i != n - 1 && s[i] == ' ' && s[i + 1] != ' '))
{
count_words++;
}
}
//This will calculate average number of letters and sentences per 100 words
float L = 100 * (count_letters / count_words);
float S = 100 * (count_sentences / count_words);
//Coleman Liau index this formula will round up to the nearest number
int formula = round(0.0588 * L - 0.296 * S - 15.8);
if (formula < 1)
{
printf("Grade 1\n");
}
else if (formula >= 16)
{
printf("Grade 16+");
}
else
{
printf("Grade %i\n", formula);
}
}
~/pset2/readability/ $ make readability
clang -ggdb3 -O0 -std=c11 -Wall -Werror -Wextra -Wno-sign-compare -Wno-unused-parameter -Wno-unused-variable -Wshadow readability.c -lcrypt -lcs50 -lm -o readability ~/pset2/readability/ $ ./readability Text: Congratulations! Today is your day. You're off to Great Places! You're off and away!