Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <cs50.h>
- #include <string.h>
- #include <ctype.h>
- #include <math.h>
- int main(int argc, string argv[])
- {
- string s = get_string("Input: "); //get user input
- float lc = 0;//lettercount
- float wc = 0;//wordcount
- float sc = 0;//sentencecount
- for (int i = 0; i < strlen(s); i++)
- {
- if (isalpha(s[i]))
- {
- lc++;
- }
- if (isspace(s[i]) && !isspace(s[i + 1]))
- {
- wc++;
- }
- if (s[i] == '.' || s[i] == '!' || s[i] == '?')
- {
- sc++;
- }
- }
- wc++;
- float L = lc / wc * 100;//letters per hundred words
- float S = sc / wc * 100;//sentences per hundred words
- float index = 0.0588 * L - 0.296 * S - 15.8;
- if (round(index) < 1)
- {
- printf("Before Grade 1\n");
- }
- else
- {
- if (round(index) >= 16)
- {
- printf("Grade 16+\n");
- }
- else
- {
- printf("\n");
- printf("Grade %i\n", (int)round(index));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement