I'm looking for some help with the readability problem from problem set 2. When I run debug50, I'm getting an error message for the text (see image). It seems that the body of the text is not being sent over to the various functions to count letters, words and sentences, which makes me think it's a scope issue? Any advice TIA!
#include <cs50.h>
#include <ctype.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
int count_letters(string text);
int count_words(string text);
int count_sentences(string text);
int main(void)
{
// prompt user for some text
string text = get_string("Text: ");
// count the number of letters, words and sentences in the text
int letters = count_letters(text);
int words = count_words(text);
int sentences = count_sentences(text);
// calculate variables L & S for Coleman-Liau index
float L = (letters / words) * 100;
float S = (sentences / words) * 100;
// compute the Coleman-Liau index
float CLindex = 0.0588 * L - 0.296 * S - 15.8;
// round result
int result = round(CLindex);
// print the grade level
if (result < 1)
{
printf("Before Grade 1\n");
}
else if (result == 1 || result <= 16)
{
printf("Grade %i\n", result);
}
else
{
printf("Grade 16+\n");
}
}
int count_letters(string text)
{
// check if characters are alphabetical and count them
int letters = 0;
for (int i = 0, j = strlen(text); i < j; i++)
{
if (isalpha(text[i]) == true)
{
letters++;
}
}
return letters;
}
int count_words(string text)
{
// count number of words
int words = 1;
for (int i = 0, j = strlen(text); i < j; i++)
{
if (isblank(text[i]) == true)
{
words++;
}
}
return words;
}
int count_sentences(string text)
{
// count number of sentences
int sentences = 0;
for (int i = 0, j = strlen(text); i < j; i++)
{
if (ispunct(text[i]) == true)
{
sentences++;
}
}
return sentences;
}