Advertisement
joseleeph

Untitled

Nov 28th, 2020
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <cs50.h>
  3. #include <string.h>
  4. #include <ctype.h>
  5. #include <math.h>
  6.  
  7. int main(int argc, string argv[])
  8. {
  9. string s = get_string("Input: "); //get user input
  10. float lc = 0;//lettercount
  11. float wc = 0;//wordcount
  12. float sc = 0;//sentencecount
  13.  
  14. for (int i = 0; i < strlen(s); i++)
  15. {
  16. if (isalpha(s[i]))
  17. {
  18. lc++;
  19. }
  20. if (isspace(s[i]) && !isspace(s[i + 1]))
  21. {
  22. wc++;
  23. }
  24.  
  25. if (s[i] == '.' || s[i] == '!' || s[i] == '?')
  26. {
  27. sc++;
  28. }
  29. }
  30.  
  31. wc++;
  32.  
  33. float L = lc / wc * 100;//letters per hundred words
  34. float S = sc / wc * 100;//sentences per hundred words
  35.  
  36. float index = 0.0588 * L - 0.296 * S - 15.8;
  37.  
  38. if (round(index) < 1)
  39. {
  40. printf("Before Grade 1\n");
  41. }
  42. else
  43. {
  44.  
  45. if (round(index) >= 16)
  46. {
  47. printf("Grade 16+\n");
  48. }
  49. else
  50. {
  51. printf("\n");
  52. printf("Grade %i\n", (int)round(index));
  53. }
  54. }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement