Coming soon - Get a detailed view of why an account is flagged as spam!
view details

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.

1
Variable always zero in my readability code
Post Flair (click to view more posts with a particular flair)
Post Body

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");

}

}

Author
Account Strength
100%
Account Age
4 years
Verified Email
Yes
Verified Flair
Yes
Total Karma
143
Link Karma
14
Comment Karma
129
Profile updated: 5 days ago
Posts updated: 9 months ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
4 years ago