Untitled

 avatar
unknown
plain_text
a year ago
2.2 kB
9
Indexable
#include <ctype.h>
#include <cs50.h>
#include <math.h>
#include <stdio.h>
#include <string.h>

        int CalOfReadingLevel(int Letters,float Words,int Sentences);
        int Number_of_Sentences (string text);
        int Number_of_Spaces (string text);
        int Number_of_Letters (string text);

int main(void)
{
    string texts = get_string("Text: ");

            // number of letters
            int NoL = Number_of_Letters (texts);
            //number of words
            int NoW = Number_of_Spaces(texts) + 1;
            //number of sentences
            int NoS = Number_of_Sentences(texts);
            //reading grade
            float ReadingLevel = CalOfReadingLevel(NoL,NoW,NoS);

    return 0;
}

int Number_of_Spaces (string text) {

int Totallengthoftext = strlen(text);
int Numberofspaces = 0;
int i;

    for (i = 0 ; i <= Totallengthoftext ; i++){

        if (text[i] == ' ') {

            Numberofspaces++;
       }

    }

    return Numberofspaces;

}


int Number_of_Letters (string text){

    int Totallengthoftext = strlen(text);

        int NoL = 0;
        int i;
           for(i=0;i <=  Totallengthoftext;i++){
                  if(isupper(text[i])){
                         NoL++;

          }else if(islower(text[i])){
                         NoL++;

           }
    }

   return NoL;


}


int Number_of_Sentences (string text){

    int Nunmberofsentences = 0;
    int totallengoftext = strlen(text);
    int i;
        for (i = 0; i <= totallengoftext;i++){

            if (text[i] == '.' || text[i] == ','||text[i] == '?'||text[i] == '!'){

                    Nunmberofsentences++;
                    i++;
            }
        }

    return Nunmberofsentences;
}

int CalOfReadingLevel(int Letters,float Words,int Sentences){


        float L =  ( Letters / Words ) *  100;
        float S =  ( Sentences / Words ) *   100;


        float index = 0.0588 * L - 0.296 * S - 15.8;


                  if (index < 1){

                    printf("Before Grade 1");
                  }else if (index >= 16){

                    printf("Grade 16+");
                  }else{

                    printf("Grade %f",ceil(index));
                  }


        return index;

}
Editor is loading...
Leave a Comment