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

//prototype for a custome function
int letters, words, sentences(string text);

int main(void)
{
    // Get text from user
    string text = get_string("TEXT: ");

    //count letters, words, scentences (string text);

    //print off index=X (gradeX)

    int index = 0;

    if (index < 1)
     {
         printf("Before G1\n");
     }

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

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

}


int letters, words, sentences(string text)
{
    //count number of letters
    int letters, sentences = 0;
    int words = 1;

    for(n = 0; strlen(text) > n; n++)

        if( isalpha text[n] );

            {
                letters++;
            }

        if ( text[n] == ' ' );

            {
                words++;
            }

        if ( text[n] == '!' || '?' || '.');

            {
                sentences++;
            }


    float zletters = letters * 100 / words;
    //need to calculate in to letters per 100 words


    float ysentences = sentences * 100 / words;
    //need to calculate to how many scentences per 100 words


    float ColemanLiau_index = 0.0588 * zletters - 0.296 * ysentences - 15.8;

    //round float Coleman-Liau index to int
    int index = round (ColemanLiau_index);

}

I get an error message on my second argument and cannot compile: int letters, words, sentences(string text) I am wondering what I have done wrong and there is any way I can test it to find that out. Thanks in advance!

0

int letters, words, sentences(string text) is not the correct function declaration, which is why your program won't compile. You will need to correct this by having only one return type, one single-word function name, and a single parameter list (if required).

So, int letters(string text), int words(string text), and int sentences(string text) would be appropriate function declarations but not all of them combined into one. If you want to modify multiple variables at once, you would need to pass all the variables you want to modify as parameters to a void functions. This would look something like: void functionName(int letters, int words, int sentences, string text). In the void function, you could then modify the values of the given variables by calling it in your function as:

int main(void) {
    ...
    functionName(letters, words, sentences, text);
    ...
}

I think this second approach is what you are trying to do, but a function can only return one variable; a void function returns none, but is what is typically used to signal that variables will be modified within.

Hope this helps. If it does, feel free to click the check mark beside my answer to accept it. But if not, let me know and I can try to help further.

1
  • Thank you for your comment. I took some course over the weekend and I hope now I am a bit more ready to tackle this problem this afternoon. – mossburger55 Jun 23 at 16:38

You must log in to answer this question.

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