0

I keep getting errors on the int i. idk what's wrong with my code

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

int main(void)

string text=get_string("Text: ");
int letters=0 , word = 1, sentence = 0;
int n= strlen;
float l, s;
for (int i = 0, i < n, i++)
{
    if (isalpha(text[i] = int i < strlen)
    {
        letters++;
    }
    if (text[i] == ' ')
    {
        word++;
    }
    if (text[i] == '.' || text[i] == '!' || text[i] == '?')
    {
        sentence++;
    }
}

float index = 0.0588 * (100* (float)letters/(float)word) - 0.296 * (100 * (float)sentence / (float)word) - 15.8;
int grade= round(index);
if (int grade <=1)
{
    printf("Before grade 1\n");
}
else (int grade > 16)
{
    printf("Grade 16+\n");
}

    printf ("%i\n", grade);

}

0

You declare int N and left it empty with strlen

It should work as

int n = strlen(text);

Or directly you can put this inside for-loop condition

Like this

for (int i = 0; i < strlen(text); i++)

Check this and if I helped you be sure to tick the answer to keep other smiling too 😃

0

You are not using strlen right.. strlen takes an input argument. Use it like strlen(x), where x is the string whose length you want to measure.

You must log in to answer this question.

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