The problem is that when i run check50 cs50/problems/2020/x/readability into the terminal, it says
:( handles questions in passage
Cause
expected "Grade 2\n", not "Grade 3\n"
Log
running ./readability...
sending input Would you like them here or there? I would not like them here or there. I would not like them anywhere....
checking for output "Grade 2\n"...
Expected Output:
Grade 2
Actual Output:
Grade 3
and it is the only thing that is wrong, there seems to be no other errors. Is it because in the sentence there are others dots at the end ? Because in the walkthrough it said that it is normal if i get more sentences in that case, and i can't see anything else changing the grade. Here is my code if needed :
#include<stdio.h>
#include<cs50.h>
#include<ctype.h>
#include<math.h>
int main(void)
{
float letters = 0;
float words = 1;
float sentences = 0;
int isalpha;
int isspace;
string text = get_string("Text :"); //ask for input
for (int i = 0; text[i] != '\0'; i++)
{
if (isalpha(text[i]) != 0)
{
letters++;
}
else if (isspace(text[i]) != 0)
{
words++;
}
else if (text[i] == '?' || text [i] == '!')
{
words--;
sentences++;
}
else if (text[i] == '.')
{
sentences++;
}
}
float avgl = (100 / words * letters); //average of letters per 100 words
float avgs = (100 / words * sentences); //average of sentences per 100 words
float index = ((0.0588 * avgl) - (0.296 * avgs) - 15.8); //calcul de l'index
int total = round(index);
if (total < 1) //check si moins de 1
{
printf("Before Grade 1\n");
}
else if (1 <= total && total <= 16) //check si entre 1 et 16
{
printf("Grade %i\n", total);
}
else if (total > 16) //check si c'est plus de 16
{
printf("Grade 16+\n");
}
}