title: Finding out readability level using Coleman-Liau index using C
body: <p>I am writing a program to find out number of letters, words, and sentences. Using these values, I am using <a href="https://en.wikipedia.org/wiki/Coleman%E2%80%93Liau_index" rel="nofollow noreferrer">Coleman-Liau index</a> to find out the article's readability level.</p>
  
  <p>I think I have a pretty solid program with the help online but I don't know why some of the errors are happening in the link below. 
  <a href="https://submit.cs50.io/check50/35e7ae7e4b968d6b06a8152f61a0e83381b376ab" rel="nofollow noreferrer">https://submit.cs50.io/check50/35e7ae7e4b968d6b06a8152f61a0e83381b376ab</a></p>
  
  <p>For context, please see <a href="https://cs50.harvard.edu/college/psets/2/readability/" rel="nofollow noreferrer">https://cs50.harvard.edu/college/psets/2/readability/</a></p>
  
  <p>Here's the code that I am having trouble with: </p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;cs50.h&gt;
  #include &lt;ctype.h&gt;
  #include &lt;string.h&gt;
  
  int letter;
  int word;
  int sentence;
  
  
  int main(void)
  {
  
  // prompt the user with the question
  
      string article = get_string("What's the article?: ");
  
  // set the length of article
  
      int n = strlen(article);
  
  // add +1 if the article starts with alphanumeric letter
  
      if (isalnum(article[0]))
      {
          word = 1;
      }
  
  // count words
  
      for (int i = 0; i &lt; n;  i++)
      {
          // count letters
  
          if (isalnum(article[i]))
          {
              letter++;
          }
  
          // count words
  
          if (i &lt; n - 1 &amp;&amp; isspace(article[i]) &amp;&amp; isalnum(article[i + 1]))
          {
              word++;
          }
  
          // count sentences
  
          if (i &gt; 0 &amp;&amp; (article[i] == '!' || article[i] == '?' || article[i] == '.') &amp;&amp; isalnum(article[i - 1]))
          {
              sentence++;
          }
  
      }
  
  // calculate Coleman-Liau index
  
      int grade = 0.0588 * (100 * letter / word) - 0.296 * (100 * sentence / word) - 15.8;
  
  // debugger
  
      printf("Letters: %i\n Words: %i\n Sentences: %i\n", letter, word, sentence);
  
  // print result
      if (grade &lt;= 1)
      {
          printf("Before Grade 1\n");
      }
      else if (grade &lt; 16)
      {
          printf("Grade %i\n", grade);
      }
      else
      {
          printf("Grade 16+\n");
      }
  }
  </code></pre>
  
  <p>As far as I can see, I can't see why some of the results are skewed. </p>