0

I keep getting EOF when I check50, but my program runs fine. It gives the correct output for every text input. I can not find a solution here. It looks fine, but when I run the check50 command I get several EOF.

Here is my code:

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

int main(void)
{
    string s = get_string("Text:  ");
    int countletter = 0;
    int countword = 0, t;
    int sentence = 0; 
    int constant = 100;
   
        
        for(int i = 0; i < strlen(s); i++) 
    {  
        if(s[i] != ' ' && s[i] != '!' && s[i] != ',' && s[i] != '.'  && s[i] != '?' && s[i] != '\'')  
            countletter++;  
    }  
    
    
    for (t = 0; s[t] != '\0'; t++)
    {
        if (s[t] == ' ' && s[t+1] != ' ')
            countword++; 
        if (s[t] == '.' || s[t] == '!' || s[t] == '?')
            sentence++;
    }
    

    float L = ((float)countletter/(countword+1))*constant; 
    float S = ((float)sentence/(countword+1))*constant;
    double index = 0.0588 * L - 0.296 * S - 15.8; 
    
      
   if (index > 1 && index < 16) 
   
   {
       printf("Grade %i\n ", (int) round(index));
       
   }
    
   if (index > 16) 
   {
       printf("Grade 16+\n");
   }
   
   if(index < 1)
   {
       printf ("Before Grade 1\n");
   }
 
   return 0; 
}

enter image description here

1 Answer 1

1

I found the mistake was in a space between %i\n and ", in the line

printf("Grade %i\n ", (int) round(index));

The problem was solved when rewriting to:

printf("Grade %i\n", (int) round(index));
2
  • Glad you solved it. Go ahead and click the check next to your answer (this one) so the system knows that this is resolved. :) Commented Jan 13, 2021 at 18:14
  • Thank you:). I will do that, but it says I must wait two days before accepting my own answer. Commented Jan 13, 2021 at 20:45

You must log in to answer this question.

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