# Can not find any mistake(CS50 online course)

This programes is to computes the approximate grade level needed to comprehend some text, per the below.

Text: Congratulations! Today is your day. Youâre off to Great Places! Youâre off and away!

And I stuck at the following two test text:
first text I should get Grade 7 but output is Grade 8,

The text used to test is:
Grade 7 : In my younger and more vulnerable years my father gave me some advice that Iâve been turning over in my mind ever since.

Grade 8 : Alice was beginning to get very tired of sitting by her sister on the bank, and of having nothing to do: once or twice she had peeped into the book her sister was reading, but it had no pictures or conversations in it, âand what is the use of a book,â thought Alice âwithout pictures or conversation?â

``````#include <stdio.h>
#include <cs50.h>
#include <string.h>
#include <ctype.h>
#include <math.h>

int countLetters(string text);
int countWords(string text);
int countSentences(string text);

int main(void)
{
string s = get_string("Text: ");

int numberOfLetters = countLetters(s);

int numberOfWords = countWords(s);

int numberOfSentences = countSentences(s);

float L = 100 * numberOfLetters / numberOfWords;
float S = 100 * numberOfSentences / numberOfWords;

int index = round(0.0588 * L - 0.296 * S - 15.8);

if (index < 1)
{
}
else if (index >= 16)
{
}
else
{
}

}

int countLetters(string text)
{
int numberOfLetters = 0 ;

for (int i = 0 ; text[i] != '\0' ; i++)
{
bool isCurrentCharAnAlpha = isalpha(text[i]);
if (isCurrentCharAnAlpha)
{
numberOfLetters++;
}
}
return numberOfLetters;
}

int countWords(string text)
{
int numberOfWords = 0 ;
for (int i = 0 ; text[i] != '\0' ; i++)
{
bool isCurrentCharAnAlpha = isalpha(text[i]);
if (isCurrentCharAnAlpha)
{
if (i == 0)
{
numberOfWords++;
}
else if (text[i - 1] == ' ')
{
numberOfWords++;
}
}
}
return numberOfWords;
}

int countSentences(string text)
{
int numberOfSentences = 0 ;
for (int i = 0 ; text[i] != '\0' ; i++)
{
if (text[i] == '.' || text[i] == '!' || text[i] == '?')
{
numberOfSentences++;
}
}
return numberOfSentences;
}
``````

Iâve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

See this post to find the backtick on your keyboard. The âpreformatted textâ tool in the editor (`</>`) will also add backticks around text.

Note: Backticks are not single quotes.

Thank you so much!

Alrighty, lets start simple. How does your result differ from what you expect?

1 Like

There are two tests text, first textâs result should be Grade 7, but it is Grade 8.
the second text should be Grade 8 but the result is Grade 9.