:( handles longer passages expected "Grade 8\n", not "Grade 7\n" HELP PLEASE
Hey guys,so this is my code. I have some trouble with it. if I enter all the texts from the cs50 assignment to check them it works fine, but when I ask to check it keeps appearing this mistake. I think my problem is with the count words, as it can't different from a word like it's which is two, or Michael's which is one. PLEASE HELP
thanks:)
#include <stdio.h>
#include <cs50.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
int main(void)
{
string text = get_string("Text: ");
int letters = 0;
int words = 0;
int sentences = 0;
// letters
for (int i = 0, li = strlen(text); i < li; i++)
{
if (isalpha(text[i]))
{
letters++;
}
}
// words
int i = 0;
do
if ((char)text[i] == ' ' || ((char)text[i] == (char)39))
{
words++;
i++;
}
else
{
i++;
}
while (i < strlen(text));
int p = words + 1;
// sentences
int a = 0;
do
{
if ((text[a] == '!' || text[a] == '?' || text[a] == '.'))
{
sentences++;
a++;
}
else
{
a++;
}
}
while (a < strlen(text));
//score
float l = (letters * 100) / p;
float s = (sentences * 100) / p;
int score = round (0.0588 * l - 0.296 * s - 15.8);
if (score >= 16)
{
printf("Grade 16+\n");
}
if (score <= -1)
{
printf("Before Grade 1\n");
}
if (score < 16 && score > -1)
{
printf("Grade %i\n", score);
}
}