title: CS50 Readability pset2 debugging
body: <p>Trying to get through cs50, stuck on readability. Can't figure out what is wrong with my code! When I plug in any length of text it is reading less than grade 1. I know it's got to be something with the counting of the letters, words, sentences but I just can't figure out where I am going wrong. Was hoping for some advice. Thank you!</p>
  <pre><code>    #include &lt;cs50.h&gt;
      #include &lt;stdio.h&gt;
      #include &lt;ctype.h&gt;
      #include &lt;string.h&gt;
      #include &lt;math.h&gt;
  
      //functions
      int count_letters(string text);
      int count_words(string text);
      int count_sentences(string text);
  
      int main(void)
      {
      //Prompt user for text
      string text = get_string(&quot;Text: &quot;);
  
      //variables
      int letters = 0;
      int words = 1;
      int sentences = 0;
  
      //calculate grade level
      float L = 100 * ((float)letters / (float)words);
      float S = 100 * ((float)sentences / (float)words);
  
      int index = round(0.0588 * L - 0.296 * S - 15.8);
      {
          if (index &gt; 16)
          {
              printf(&quot;Grade 16+\n&quot;);
          }
          else if (index &lt; 1)
          {
              printf(&quot;Before Grade 1\n&quot;);
          }
          else
          {
              printf(&quot;Grade %i\n&quot;, index);
          }
      }
  
      }
      //Count number of letters
      int letters = 0;
      int count_letters(string text)
      {
      for (int i = 0; i &lt; strlen(text); i++)
       {
           if (isalpha(text[i]))
           {
              letters++;
           }
       }
       return letters;
      }
  
       //Count number of words
      int words = 1;
      int count_words(string text)
      {
      for (int i = 0; i &lt; strlen(text); i++)
      {
          if (isspace(text[i]))
          {
              words++;
          }
      }
      return words;
      }
  
      //Count number of sentences
      int sentences = 0;
      int count_sentences(string text)
      {
      for (int i = 0; i &lt; strlen(text); i++)
       {
          if ((text[i] == '!') || (text[i] == '?') || (text[i] == '.'))
          {
              sentences++;
          }
       }
       return sentences;
      }
  </code></pre>