Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <cs50.h>
- #include <ctype.h>
- #include <string.h>
- #include <math.h>
- int main(void)
- {
- string word;
- word = get_string("Text: ");
- //Count total letters
- int numLetters=0;
- for (int i=0; i<strlen(word); i++)
- {
- if (isalpha(word[i]) != 0)
- {
- numLetters++;
- }
- }
- int spaces=0;
- //Count words (spaces)
- for (int i=0; i<strlen(word); i++)
- {
- if (word[i] == ' ')
- {
- spaces++;
- }
- }
- int words = spaces+1;
- //Count sentences
- int sentences=0;
- for (int i=0; i<strlen(word); i++)
- {
- if (word[i] == '.' || word[i] == '!' || word[i] == '?')
- {
- sentences++;
- }
- }
- //printf("%i\n", numLetters);
- //printf("%i\n", words);
- //printf("%i\n", sentences);
- float L=0;
- float S=0;
- L = 100.0 * numLetters / words;
- S = 100.0 * sentences / words;
- float index=0;
- index = 0.0588 * L - 0.296 * S - 15.8;
- int grade=0;
- grade = round(index);
- if (grade<1)
- {
- printf("Before Grade 1\n");
- }
- else if (grade>=16)
- {
- printf("Grade 16+\n");
- }
- else
- {
- printf("Grade %i\n", grade);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement