diff options
Diffstat (limited to 'wk2/pset/readability')
-rw-r--r-- | wk2/pset/readability/readability.c | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/wk2/pset/readability/readability.c b/wk2/pset/readability/readability.c new file mode 100644 index 0000000..89f675e --- /dev/null +++ b/wk2/pset/readability/readability.c @@ -0,0 +1,52 @@ +#include <cs50.h> +#include <math.h> +#include <stdio.h> + +int main(void) +{ + string text = get_string("Text: "); + float s = 0; + float w = 1; + float l = 0; + int i = 0; + char c; + do + { + c = text[i]; + int j = c; + i++; + if (c == '.' || c == '!' || c == '?') + { + s++; + } + else if (c == ' ') + { + w++; + } + else if ((64 < j && j < 91) || (96 < j && j < 123)) + { + l++; + } + } + while (c != '\0'); + // printf("s: %f w: %f l: %f\n", s, w, l); + float L = (float) (l / w) * 100; + float S = (double) (s / w) * 100; + float index = 0.0588 * L - 0.296 * S - 15.8; + if (index < 1) + { + printf("Before Grade 1\n"); + } + else + { + int ans = round(index); + if (ans >= 16) + { + printf("Grade 16+\n"); + } + else + { + printf("Grade %i\n", ans); + } + } +} |