0

I am trying to complete problem set 2 for cs50 and I am having trouble fixing my program , can anyone tell me why?

#include <stdio.h>

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

int main(void)

{ string s = get_string("Text: "); int num_words, num_sentences, num_letters; num_words = num_sentences = num_letters = 0; for (int i = 0, len = strlen(s); i < len; i++) { if (isalpha(s[i])) num_letters++; if ((i == 0 && s[i] != ' ') || (i != len - 1 && s[i] == ' ' && s[i + 1] != ' ')) num_words++; if (s[i] == '.' || s[i] == '?' || s[i] == '!') num_sentences++; } float L = (num_letters / (float) num_words) * 100; float S = (num_sentences / (float) num_words) * 100; int index = round(0.588 * L - 0.296 * S - 15.8);

if (index < 1)
    printf("Before Grade 1\n");

else if (index >= 16)
    printf("Grade 16+\n");

else
    printf("Grade %i\n", index);

}

1

The "slug" refers to the command line argument supplied to cs50, not to anything in the code. The command from the spec is

check50 cs50/problems/2020/x/readability

Verify it is typed correctly (or copy/paste from the spec or from this post).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .