• This topic is empty.
Viewing 1 post (of 1 total)
  • Author
    Posts
  • #83
    admin
    Keymaster
      
      
      #include <stdio.h>
      #include <cs50.h>
      #include <ctype.h>
      #include <string.h>
      int main(void)
      {
          string enterword = get_string("input: ");
          int t = strlen(enterword);
          printf("%i\n", t);
          int counter = 0;
          for(int i = 0; i<= t; i++)
          {
      
               if (enterword == '.'|| enterword == '!' || enterword == '?'){
               counter = counter + 1;}
          }
               printf("number of lines %i\n",counter);
      
               int wordcounter = 1;
               for (int i = 0; i<= t; i++)
               {
                   if (enterword == ' ' ){
                       wordcounter = wordcounter + 1;
      
                   }
               }
               printf("total words %i\n", wordcounter);
               int lettercounter = 0;
          for (int i = 0; i <= t; i++){
               if (isalpha (enterword)) {
              lettercounter++;
               }
      
            }
            printf("number of letters %i\n", lettercounter);
            int L = (lettercounter / wordcounter) * 100;
            printf("L index: %i\n",L);
            int S = (counter / wordcounter) * 100;
            printf("S index: %i\n",S);
            int index = (0.0588 * L) - (0.296 * S) - 15.8;
            printf("CI: %i\n",index);
      
      
      }
      

      For the above code, while I could see the number of letters, words, sentences computed correctly, but not Coleman-Liau Index. Instead of Grade 5, it is showing Grade I (CI) in this example: https://www.canva.com/design/DAE0L-QIgQ0/M19PsHu5Di-MsEyNgmT-WQ/view?utm_content=DAE0L-QIgQ0&utm_campaign=designshare&utm_medium=link&utm_source=sharebutton

       


      Reply


      https://edstem.org/us/courses/176/discussion/978225?comment=2213954


      Getting the output in decimal form with float

      
      
      int lettercounter(string enteredword);
      int wordcounter(string enteredword);
      int sentencecounter(string enteredword);
      int main(void)
      {
          string enteredword = get_string("enter word:"); int y = lettercounter(enteredword);
          printf("number of alphabetical characters: %i\n", y);
          int f = wordcounter(enteredword);
          printf("number of words: %i\n", f);
          int s = sentencecounter(enteredword);
          printf("number of sentences: %i\n",s);
          float L = ((float)(y/f)) * 100;
          printf("average letter per 100 word:%f",L);
      }
      
      

      I guess there is something wrong with:

      
      
      float L = ((float)(y/f)) * 100;
      

      Not getting the output in decimal form.


      Reply


      https://edstem.org/us/courses/176/discussion/1884170?comment=4306771[learn_press_profile]

    Viewing 1 post (of 1 total)
    • You must be logged in to reply to this topic.
    Scroll to Top