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
|
#include <cs50.h>
#include <stdio.h>
#include <math.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++;
//printf("%i ", j);
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;
//printf("L: %f, S: %f, Grade: %f\n", L, S, index);
if (index)
int ans = round(index);
printf("Grade: %i\n", ans);
}
/*
*DONE* Your program must prompt the user for a string of text using get_string.
*DONE* Your program should count the number of letters, words, and sentences
in the text. You may assume that a letter is any lowercase
character from a to z or any uppercase character from A to Z,
any sequence of characters separated by spaces should count as
a word, and that any occurrence of a period, exclamation point,
or question mark indicates the end of a sentence.
Your program should print as output "Grade X" where X is the grade
level computed by the Coleman-Liau formula, rounded to the nearest
integer.
If the resulting index number is 16 or higher (equivalent to or
greater than a senior undergraduate reading level), your program
should output "Grade 16+" instead of giving the exact index
number. If the index number is less than 1, your program should
output "Before Grade 1".
*/
|