Anyone knows why i get this error?
:) readability.c exists
:) readability.c compiles
:( handles single sentence with multiple words
expected "Grade 7\n", not "Grade 8\n"
:) handles punctuation within a single sentence
:) handles more complex single sentence
:) handles multiple sentences
:) handles multiple more complex sentences
:) handles longer passages
:) handles questions in passage
:) handles reading level before Grade 1
:) handles reading level at Grade 16+
#include <cs50.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
int count_letters(int n, string text);
int count_words(int n, string text);
int count_sentences(int n, string text);
void coleman(int n, string ImputText);
int main (void)
{
//n variable is lenght of the string
int n = 0;
string ImputText = 0;
ImputText = get_string("Text :");
n = strlen(ImputText);
//valling functions
count_letters(n, ImputText);
count_words(n, ImputText);
count_sentences(n, ImputText);
coleman(n, ImputText);
return 0;
}
// function counting letters
int count_letters(int n, string text)
{
int sumletters = 0;
for ( int i = 0; i < n; i++)
{
if ( isalpha(text[i]) != 0)
{
sumletters++;
}
}
return sumletters;
}
// function for counting words
int count_words(int n, string text)
{
int sumwords = 1;
for ( int i = 0; i < n; i++)
{
if (text[i] == ' ')
{
sumwords++;
}
}
return sumwords;
}
// function counting sentences
int count_sentences(int n, string text)
{
int sumsentences = 0;
for ( int i = 0; i < n; i++)
{
if (text[i] == '.' || text[i] == '!' || text[i] == '?')
{
sumsentences++;
}
}
return sumsentences;
}
/* Coleman-Liau index function - index = 0.0588 * L - 0.296 * S - 15.8
Here, L is the average number of letters per 100 words in the text,
and S is the average number of sentences per 100 words in the text.
Modify readability.c so that instead of outputting the number of letters, words, and sentences,
it instead outputs the grade level as given by the Coleman-Liau index (e.g. "Grade 2" or "Grade 8").
Be sure to round the resulting index number to the nearest whole number!
If the resulting index number is 16 or higher (equivalent to or greater than a senior undergraduate reading level),
your program should output "Grade 16+" instead of giving the exact index number. If the index number is less than 1,
your program should output "Before Grade 1".
*/
void coleman (int n,string ImputText)
{
float l = (count_letters(n, ImputText)* 100)/ count_words(n, ImputText);
float s = (count_sentences(n, ImputText)*100) / count_words(n, ImputText);
int index =round ( (0.0588 * l) - (0.296 * s) - 15.8);
if (index >= 16)
{
printf ("Grade 16+\n");
}
else if (index < 1)
{
printf ("Before Grade 1\n");
}
else
{
printf("Grade %i\n", index);
}
}