Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cs50.h>
- #include <stdio.h>
- #include <ctype.h>
- #include <string.h>
- #include <math.h>
- int count_letters(string t);
- int count_words(string t);
- int count_sentences(string t);
- int formula(int l, int w, int s);
- int main(void)
- {
- string text = get_string("Text: ");
- int l_ = count_letters(text);
- int w_ = count_words(text);
- int s_ = count_sentences(text);
- int index = formula(l_, w_, s_);
- if (index >= 16)
- {
- printf("Grade 16+\n");
- }
- else if (index < 16 && index >= 1)
- {
- printf("Grade %i\n", index);
- }
- else
- {
- printf("Before Grade 1\n");
- }
- }
- int count_letters(string t)
- {
- int letters = 0;
- int len = strlen(t);
- for(int x = 0; x < len; x++)
- {
- if (isalpha(t[x]) != 0)
- {
- letters++;
- }
- }
- return letters;
- }
- int count_words(string t)
- {
- int spaces = 0;
- int len = strlen(t);
- for(int x = 0; x < len; x++)
- {
- if (t[x] == 32)
- {
- spaces++;
- }
- }
- return spaces + 1;
- }
- int count_sentences(string t)
- {
- int sentences = 0;
- int len = strlen(t);
- for(int x = 0; x < len; x++)
- {
- if(t[x] == 33 || t[x] == 46 || t[x] == 63)
- {
- sentences++;
- }
- }
- return sentences;
- }
- int formula(int l, int w, int s)
- {
- float L = (l / w) * 100;
- float S = (s / w) * 100;
- float index = 0.0588 * L - 0.296 * S - 15.8;
- return round(index);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement