• Skip to main content
  • Skip to footer

SoftwareProg.com

Software programming learning aide

  • Blog
    • Discussion
  • News
  • CS50’s Introduction to Computer Science by Harvard University on Edx
    • Week 1
    • Week 2
    • Week 3
    • Week 4
    • Week 5

Problem computing Coleman-Liau Index/Getting the output in decimal form with float

CS50 threads to aide as a supplementary resource › Forums › CS50’s Introduction to Computer Science by Harvard University on Edx › Week 2 › Problem computing Coleman-Liau Index/Getting the output in decimal form with float

Tagged: arrays, c, float type, Integer divison

  • This topic is empty.
Log In Register Lost Password
Viewing 1 post (of 1 total)
  • Author
    Posts
  • January 1, 2022 at 7:53 am #83
    admin
    Keymaster


      Copy Code
      Copied
      Use a different Browser

      
      
      #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


      Copy Code
      Copied
      Use a different Browser

      
      
      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:


      Copy Code
      Copied
      Use a different Browser

      
      
      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]

    • Author
      Posts
    Log In Register Lost Password
    Viewing 1 post (of 1 total)
    • You must be logged in to reply to this topic.
    Log In

    Log in / Register

    Initiative by Digital Splendid OPC Pvt. Ltd.