Created
January 3, 2021 07:24
-
-
Save jibachhydv/a764ac6e4e6540c6a3e78506d0383e99 to your computer and use it in GitHub Desktop.
CS50x 2020 Readability
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cs50.h> | |
#include <stdio.h> | |
#include <math.h> | |
#include <ctype.h> | |
#include <string.h> | |
#include <math.h> | |
int main(void) | |
{ | |
// Get the text | |
string text = get_string("Text: "); | |
// counter for number of letter | |
int letterCount = 0; | |
// Counter for number of word | |
int wordCount = 1; | |
// Counter for sentence count | |
int sentenceCount = 0; | |
for (int i = 0 ; i < strlen(text); i++) | |
{ | |
// Check Whether Character is alphabetical or not | |
if (isalpha(text[i])) | |
{ | |
letterCount++; | |
} | |
// Check for space | |
if (isspace(text[i])) | |
{ | |
wordCount++; | |
} | |
// Check for sentence elimination letter | |
if (text[i] == 46 || text[i] == 33 || text[i] == 63) | |
{ | |
sentenceCount++; | |
} | |
} | |
// printf("Number of letter: %i\n", letterCount); | |
// printf("Number of word: %i\n", wordCount); | |
// printf("Number of Sentences: %i\n", sentenceCount); | |
float averageLetter = ((float) letterCount/(float) wordCount) * 100; | |
float averageWord = ((float) sentenceCount/(float) wordCount) * 100; | |
// printf("%.2f\n", averageLetter); | |
// printf("%.2f\n", averageWord); | |
int index = round(0.0588 * averageLetter - 0.296 * averageWord - 15.8); | |
// printf("Index is: %i\n", index); | |
if (index >= 16) { | |
printf("Grade 16+\n"); | |
} else if (index < 1) { | |
printf("Before Grade 1\n"); | |
} else { | |
printf("Grade %i\n", index); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment