Guest User

Untitled

a guest
Apr 20th, 2020
348
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.33 KB | None | 0 0
  1. // Command libraries
  2. #include <cs50.h>
  3. #include <stdio.h>
  4. #include <string.h>
  5. #include <ctype.h>
  6. #include <math.h>
  7.  
  8. // Main program
  9. int main(void)
  10. {
  11.     // Prompting user for text
  12.     string text_prompt = get_string("Enter text for evaluation: ");
  13.  
  14.     // Count of TOTAL characters in string (anything)
  15.     int total_length = strlen(text_prompt);
  16.  
  17.     // Setting up and implementing the counters
  18.     int letter_count = 0;
  19.     int word_count = 1;
  20.     int sentence_count = 0;
  21.     for(int n = 0; n < total_length; n++)
  22.     {
  23.         if (isalpha(text_prompt[n]))
  24.         {
  25.             letter_count++;
  26.         }
  27.         if (isblank(text_prompt[n]))
  28.         {
  29.             word_count++;
  30.         }
  31.         if ((text_prompt[n] == '!') || (text_prompt[n] == '?') || (text_prompt[n] == '.'))
  32.         {
  33.             sentence_count++;
  34.         }
  35.     }
  36.  
  37.     // Setting up grade level calculation
  38.     float avg_letters = (100 * letter_count) / word_count;
  39.     float avg_sentences = (100 * sentence_count) / word_count;
  40.     int index = round(((0.0588 * avg_letters) - (0.296 * avg_sentences) - 15.8));
  41.  
  42.     // Printing result to user
  43.     if (index > 16)
  44.     {
  45.         printf("Grade 16+\n");
  46.     }
  47.     else if (index < 1)
  48.     {
  49.         printf("Before Grade 1\n");
  50.     }
  51.     else
  52.     {
  53.         printf("Grade %d\n", index);
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment