0

the program runs quite well but not accurate when check50 is applied

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

int main(void)
{
    string s = get_string("Input Text:");
    int num_words = 0;
    int num_letters = 0;
    int num_sentences = 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.0588 * L - 0.296 * S - 15.0);
    if(index < 1)
        printf("Before Grade 1 \n");
    else if(index >= 16)
        printf("Grade 16+\n");
    else
        printf("Grade %i\n", index);
}

can anyone help out

0

It's the simplest things that are the hardest to find! ;-D

You have a typo in your index calculation and an extra space in the "below grade 1" printout.

Try not to leave any bruising from that head slap. ;-)

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

5
  • thank you but still have the same issues, the program runs but the output of a grade 9 sentence comes out as grade 10 and so on – Sawyerr Mayowa Aug 10 '20 at 11:17
  • It ran fine for me after I changed the 0 to an 8. – Cliff B Aug 10 '20 at 18:29
  • please i dont understand what you mean change 0 to 8? is it the increment "int i = 0" – Sawyerr Mayowa Aug 11 '20 at 21:39
  • The typo was in the formula. It's - 15.8, not - 15.0 – Cliff B Aug 12 '20 at 17:57
  • Oh i see thank you very much – Sawyerr Mayowa Aug 14 '20 at 11:31

You must log in to answer this question.

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