Advertisement
ssoni

readability.c

Feb 8th, 2022
973
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.30 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <cs50.h>
  3. #include <ctype.h>
  4. #include <string.h>
  5. #include <math.h>
  6.  
  7. int main(void)
  8. {
  9.     string word;
  10.     word = get_string("Text: ");
  11.  
  12.     //Count total letters
  13.     int numLetters=0;
  14.     for (int i=0; i<strlen(word); i++)
  15.     {
  16.         if (isalpha(word[i]) != 0)
  17.         {
  18.             numLetters++;
  19.         }
  20.     }
  21.  
  22.     int spaces=0;
  23.     //Count words (spaces)
  24.     for (int i=0; i<strlen(word); i++)
  25.     {
  26.         if (word[i] == ' ')
  27.         {
  28.             spaces++;
  29.         }
  30.     }
  31.     int words = spaces+1;
  32.  
  33.     //Count sentences
  34.     int sentences=0;
  35.     for (int i=0; i<strlen(word); i++)
  36.     {
  37.         if (word[i] == '.' || word[i] == '!' || word[i] == '?')
  38.         {
  39.             sentences++;
  40.         }
  41.     }
  42.     //printf("%i\n", numLetters);
  43.     //printf("%i\n", words);
  44.     //printf("%i\n", sentences);
  45.  
  46.     float L=0;
  47.     float S=0;
  48.     L = 100.0 * numLetters / words;
  49.     S = 100.0 * sentences / words;
  50.     float index=0;
  51.     index = 0.0588 * L - 0.296 * S - 15.8;
  52.     int grade=0;
  53.     grade = round(index);
  54.  
  55.     if (grade<1)
  56.     {
  57.         printf("Before Grade 1\n");
  58.     }
  59.     else if (grade>=16)
  60.     {
  61.         printf("Grade 16+\n");
  62.     }
  63.     else
  64.     {
  65.         printf("Grade %i\n", grade);
  66.     }
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73. }
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement