# CS50x Problem Set 2 (Readability)

Hello reader! So I am currently on the readabililty project in problem set 2. I almost meet all of the checkpoints. However, I keep failing the one below that has a red color:

This is as you can see, the only one I am failing. But, I can’t find the cause of this problem. Help would be appreciated, and thanks in advance!

Code:

``````#include <stdio.h>
#include <cs50.h>
#include <string.h>
#include <ctype.h>
#include <math.h>

float count_letters(string text, int str_length);
float count_words(string text, int str_length);
float count_sens(string text, int str_length);

int main(void)
{
// Prompt user for text
string text = get_string("Text: ");

// Find length of text
int length = strlen(text);

// Find the number of letters in text
float letter_count = count_letters(text, length);

// Find the number of words in text
float word_count = count_words(text, length);

// Find the number of sentances in text
int sen_count = count_sens(text, length);

// Calculate the average number of letters and sentances per 100 words
int L = round((100 / word_count) * letter_count);
int S = round((100 / word_count) * sen_count);

// Calculate and show grade level
float index = 0.0588 * L - 0.296 * S - 15.8;
index = round(index);

if (index < 1)
{
}
else if (index > 0 && index < 16)
{
}
else
{
}
}

float count_letters(string text, int str_length)
{
int letters = 0;

// Checks every character
for (int i = 0; i < str_length; i++)
{
// Checks if it is a letter
if (isalpha(text[i]) != 0)
{
// If true, add one to number of letters
letters++;
}
}
// Returns the number of letters
return letters;
}

float count_words(string text, int str_length)
{
int words = 0;

// Checks every character
for (int i = 0; i < str_length; i++)
{
// Checks for a space
if(text[i] == 32)
{
// If true, Add one to number of words
words++;
}
}
// Adds word from the end of text
words++;

// Returns the number of words
return words;
}

float count_sens(string text, int str_length)
{
int sentences = 0;

// Checks each character
for (int i = 0; i < str_length; i++)
{
// Checks for end of sentance
if (text[i] == '!' || text[i] == '.' || text[i] == '?')
{
// If true, add one to the number of sentences
sentences++;
}
}
// Returns number of sentences
return sentences;
}
``````

Turns out I found out the solution! In case anyone has the same issue, the solution was to change L and S to a float, and then take out the round function in the equation. Hopefully, that makes sense!

HI @Josh641 !

Glad you were able to figure it out.
In the future, you will probably have better luck with responses if you post your cs50 related questions in their discords and chats.

They have tens of thousands of current students and alumni from the course on their platforms.
You can find a complete list of platforms on their homepage

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.