From a2682d25c6cd0e069ff73a43df74c17a63caabac Mon Sep 17 00:00:00 2001 From: Fudgerboy <91767657+Fudgerboy@users.noreply.github.com> Date: Sat, 17 Feb 2024 22:59:23 +0000 Subject: Sat, Feb 17, 2024, 2:59 PM -08:00 --- wk2/pset/readability/readability.c | 52 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 wk2/pset/readability/readability.c (limited to 'wk2/pset/readability/readability.c') 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 +#include +#include + +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); + } + } +} -- cgit v1.2.3