This is my 1st post here. I am taking CS50 and I am stuck trying to figure out why the results for this weeks problem set are delivering inconsistent results.
My code is below. It passes most of the tests but on 3 tests, it reports back a grade level one below where it should. I am almost there but cannot figure out where it is reporting inconsistently.
The tests it fails on are here: https://submit.cs50.io/check50/8fdd8542fdfb2e9da21e41aecc3d31f370f18b34
Some help pointing me in the right direction would be appreciated.
int main(void) { string s = get_string("Text: "); printf("Output: ");
int main(void)
{
string s = get_string("Text: ");
printf("Output: ");
int letter_count = 0;
for (int i = 0, n = strlen(s); i < n; i++)
{
if(isalpha(s[i]) !=0)
letter_count++;
}
int word_count = 1;
for (int i = 0, n = strlen(s); i < n; i++)
{
if((s[i]) == ' ')
word_count++;
}
int sentence_count = 0;
for (int i = 0, n = strlen(s); i < n; i++)
{
if(s[i] == '.' || s[i] == '!' || s[i] == '?')
sentence_count++;
}
int L = letter_count * 100 / word_count;
int S = sentence_count * 100 / word_count;
int grade = 0.0588 * L - 0.296 * S - 15.8;
if (grade < 1)
printf("Before Grade 1\n");
else if (grade >= 16)
printf("Grade 16+\n");
else
printf("Grade %i\n", grade);
}
}