-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathReadability_Grade_Evaluator.c
67 lines (67 loc) · 1.17 KB
/
Readability_Grade_Evaluator.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include<cs50.h>
#include<stdio.h>
#include<string.h>
#include<ctype.h>
#include<math.h>
int count_letters(string t, int l)
{
int i, c = 0;
for (i = 0; i < l; ++i)
{
if (isalpha(t[i]))
{
c++;
}
}
return c;
}
int count_words(string t, int l)
{
int i, c = 1;
for (i = 0; i < l; ++i)
{
if (t[i] == ' ')
{
c++;
}
}
return c;
}
int count_sentences(string t, int l)
{
int i, c = 0;
for (i = 0; i < l; ++i)
{
if (t[i] == '.' || t[i] == '!' || t[i] == '?')
{
c++;
}
}
return c;
}
int main(void)
{
int cl, wl, sl, index;
float L, S, in;
string text = get_string("Text:");
int l = strlen(text);
cl = count_letters(text, l);
wl = count_words(text, l);
sl = count_sentences(text, l);
L = ((float)cl / (float)wl) * 100;
S = ((float)sl / (float)wl) * 100;
in = 0.0588 * L - 0.296 * S - 15.8;
if (in < 1)
{
printf("Before Grade 1\n");
}
else if (in > 16)
{
printf("Grade 16+\n");
}
else
{
index = round(in);
printf("Grade %d\n", index);
}
}