0

I keep getting this same error message readability.c:31:1: error: expected identifier or '(' { Please Help! I put my program below:

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

int get_index(string s);

int main()
{
    string text = get_string("Text: ");
    int index = get_index(text);

    if (index < 1)
    {
        printf("Before Grade 1\n");
    } 
    else if (index >= 16)
    {
        printf("Grade 16+\n");
    } 
    else
    {
        printf("Grade %d\n", index);
    }

    return 0;
}

int get_index(string s);
{
    int letters = 0, sentences = 0, words = 0;

    for (int i = 0; i < strlen(s); i++)
    
        char ch = s[i];
        
    if (isalpha(ch))
    {
        letters++;
    }
    if (isspace(ch))
    {
        words++;
    }
    if (ch == '.' || ch == '!' || ch == '?')
    {
        sentences++;
    }
    words++

    float L = (letters * 100.0f) / words;
    float S = (sentences * 100.0f) / sentences;
    return round(0.0588 * L - 0.296 * S - 15.8);
}
1

Simple syntax error.

int get_index(string s);

This is the first line of the actual function, not a signature-only line. There should not be a semicolon. If this were a signature-only line at the top of the file, then you would need the semicolon.

1
  • It worked! Thank you so much. Jan 9 at 16:31

You must log in to answer this question.

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