0

This is my code and I'am stuck at the last stage where index to be calculated. HOw to fix that?

Error pops up: ( readability.c:50:42: error: pointer cannot be cast to type 'float') +++++++++++++++++++++++++++++++++++++++

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

  int count_letters (string l)

{
    int b = 0;

    while (*l)
        if (isalpha (*l++))
            b++;

    return b;

}

  int count_words (string w)

{
    int a = 0;

    while (*w)
        if (isspace (*w++))
            a++;

    return a + 1;
}


  int count_sentences (char ch[])

{
    int count = 0;
    int i;
    i = 0;
    while(ch[i] != '\0')

    {
        if(ch[i] == '.' || ch[i] == '?' || ch[i] == '!')
            count++;
        i++;
    }

    return count;
}

   float Grade = 0.0588 * (100 * (float) count_letters / (float) count_words) - 0.296 * (100 * (float) count_sentences / (float) count_words) - 15.8

   int main (void)


{
    string text = get_string ("Text: ");


    printf ("%d letter (s)\n", count_letters(text));
    printf ("%d word (s)\n", count_words(text));
    printf ("%d sentence (s)\n", count_sentences(text));
    printf ("Grade %f\n", (int) round(Grade));

}
0

count_letters, count_words and count_sentences are function names, not variables. They are not being used correctly. It looks like you're trying to use them like variables. Each needs a parameter to be called.

Next, line 50 is not within main or any function. This will get trapped as an error in the next compile phase.

You must log in to answer this question.

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