When I submit my readability code check50 says:
Expected Output:
Before Grade 1
Actual Output:
Before Grade 1
Expected Output:
Grade 16+
Actual Output:
Grade 16+
Since my program outputs what is expected, I am not sure how to fix this.
int main(void)
{
int i, letter = 0, word = 1, sent = 0;
// prompt user for text
string text = get_string("Text: ");
// iterate text for calculations
for (i = 0; text[i] != '\0'; i++)
{
if ((text[i] >= 'A' && text[i] <= 'Z') || (text[i] >= 'a' && text[i] <= 'z')) // count letters
{
letter++;
}
else if (text[i] == ' ') // count words
{
word++;
}
else if (text[i] == '.' || text[i] == '!' || text[i] == '?') // count sentances
{
sent++;
}
}
float l = (100.00 / word) * letter;
float s = (100.00 / word) * sent;
float index = 0.0588 * l - 0.296 * s - 15.8;
int grade = round(index);
if (grade < 1)
{
printf("Before Grade 1");
}
else if (grade >= 16)
{
printf("Grade 16+");
}
else
{
printf("Grade %i\n", grade);
}
return 0;
}