This post has been de-listed
It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.
so i have a problem figuring out what is wrong with my readability code, everything seems okay and I checked it with debug50 but somehow the variable (S) always equals 0, no matter the numbers were, even i ran my debug50 and got the numbers of (sentences) and (words) and calculate it its impossible that it would be (0). so how is it always (0)? or in other words what is wrong with my code?!
#include <stdio.h>
#include <cs50.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include <math.h>
int main(void)
{
// getting the text from the user.
string text = get_string("Text: ");
int letters = 0;
int words = 1;
int sentences = 0;
// looping the text to get the number of letters/ wordds/ sentences
for (int i = 0, n = strlen(text); i < n; i )
{
// checking if the letter is alphabatical character
if (isalpha(text[i]))
{
letters ;
}
// checking if its a blank(space) and add one to the words counter if it is
if (isblank(text[i]))
{
words ;
}
// checking if there is a (!), (.) or (?) and adding one to the sentence counter
if (text[i] == 46 || text[i] == 63 || text[i] == 33)
{
sentences ;
}
}
// calculating the L and the S for the formula
float L = letters / words * 100;
float S = sentences / words * 100;
// calculating the formula
float index = 0.0588 * L - 0.296 * S - 15.8;
// rounding the index to become an integer
int grade = round(index);
// checking and printing the grades as required
if (grade < 0)
{
printf("Before Grade 1\n");
}
else if (grade <= 16 && grade > 0)
{
printf("Grade %i\n", grade);
}
else
{
printf("Grade 16 \n");
}
}
Subreddit
Post Details
- Posted
- 4 years ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/cs50/commen...