blob: 89f675e7863ca5fe0a5defe4ee460cbecd1bf25d (
plain)
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
|
#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);
}
}
}
|