Hi I am stuck on readability and am not sure what i am doing wrong
$ ./readability
Text: one fish. two fish. red fish. blue fish
8
3
42
13
Grade 13
and my code:
#include <stdio.h>
#include <math.h>
#include <cs50.h>
#include <string.h>
#include <ctype.h>
int main() {
string text = get_string("Text: ");
int sentences = 0;
int numberOfCharacters = strlen(text);
int words = 0;
bool foundLetter = false;
for (int i = 0; i < numberOfCharacters; i++) {
if (text[i] == ' ') {
foundLetter = false;
} else if (foundLetter == false) {
words++;
foundLetter = true;
}
}
printf("%d\n", words);
for (int x=0; x < numberOfCharacters; x++) {
if (text[x] == '!' || text[x] == '.' || text[x] == '?') {
sentences += 1;
}
}
printf("%d\n", sentences);
for (int a=0; a < numberOfCharacters; a++) {
if (text[a]=='.') {
numberOfCharacters++;
}
}
printf("%d\n", numberOfCharacters);
float averageWords = sentences / words * 100;
float averageLetters = numberOfCharacters / words * 100;
float nonRoundedIndex = 0.0588 * averageLetters - 0.296 * averageWords - 15.8;
int index = round(nonRoundedIndex) - 1;
printf("%d\n", index);
if (index >= 16) {
printf("Grade 16+\n");
} else if (index <= 1) {
printf("Before Grade 1 \n");
} else {
printf("Grade %d \n", index);
}
}